Creating Valuesets From External File(dict & datafile)

Discussions about CSEntry
Post Reply
munirmdee1
Posts: 75
Joined: August 17th, 2015, 9:32 am
Location: Dar es Salaam, Tanzania

Creating Valuesets From External File(dict & datafile)

Post by munirmdee1 »

I'm having a problem here about using an ARRAY to create Valuesets as follows;
I have a dictionary called COMPANY.DCF, and its data file COMPANY.DAT, I use this as an external dictionary to load all companies that fall in a certain categories. So after entering company's category code, then the program use this dictionary and its data file to load all the companies that fall within that category. In this dictionary we have variables namely, ccode(company code),catcode(category code), and cname(company name). ccode and catcode are all id fields.
The variables that I use to create the value sets from the loaded companies. I declared them in the GLOBAL as ARRAYS with sizes, example:

- array alpha(20) comp_name(20);
- array comp_code(20);

I assigns all company names to variable comp_name(i) and all company codes to comp_code(i), so that I can create a new value sets according to the loaded companies. Example:

i = 1;
While (loadcase(COMPANY)) Do
if Q204 = catcode then // Q204 is where category code is entered
comp_code(i) = ccode;
comp_name(i) = cname;
i=i+1;
endif;
Enddo;
SetValueSet(Q205,comp_code,comp_name);

Now the problems comes when the number of companies loaded is less than the size of those two arrays I declared in the GLOBAL, Arrays size is 20, assume number of companies loaded is 13, so when I assign those arrays to a value set of Q205 as it seen above, after 13th Value then it add other remaining 7 empty value sets (7 empty spaces) to make it 20, so I get a long list of 13 value sets and 7 more empty value sets (7 empty spaces).

My question is how to get rid of those seven empty value sets (empty spaces)?, or is there any possibility to change Array size after been declared in the GLOBAL before assigning new value sets to fit the number of companies loaded?

I can count number of cases loaded in the while do loop, but how can I change array size to the number of cases I counted?

Thanks, hope to hear from you soon.
Munir Mdee
Software Programmer
National Bureau of Statistic (NBS)
Jakaya Kikwete Road,
P.O.Box 2683,
Dodoma,TANZANIA
Mob: +255 755 740090
Email: munir.mdee@nbs.go.tz
munirmdee@gmail.com
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Creating Valuesets From External File(dict & datafile)

Post by josh »

You need to mark the end of the value set by adding a entry of notappl to the array of codes. Just add the line:

comp_code(i) = notappl;

after you exit the loop and right before the call to setvalueset. At this point i will be the index of the next available entry in the array, i.e. one past the last entry. When setvalueset finds an entry in the array with the code set to notappl it stops adding values to the value set.
munirmdee1
Posts: 75
Joined: August 17th, 2015, 9:32 am
Location: Dar es Salaam, Tanzania

Re: Creating Valuesets From External File(dict & datafile)

Post by munirmdee1 »

Wwaaoouu, thank you Josh, it worked fine, I wonder how I couldn't figure it out...thank you very much..problem solved
Munir Mdee
Software Programmer
National Bureau of Statistic (NBS)
Jakaya Kikwete Road,
P.O.Box 2683,
Dodoma,TANZANIA
Mob: +255 755 740090
Email: munir.mdee@nbs.go.tz
munirmdee@gmail.com
Post Reply