Adding same fields in different cases

Discussions about tools to complement CSPro data processing
Forum rules
New release: CSPro 8.0
Post Reply
Bhupender11
Posts: 63
Joined: May 15th, 2018, 1:18 am

Adding same fields in different cases

Post by Bhupender11 »

Dear CSPRO Team,

How can I add same numeric field from different cases into another dictionary field.
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Adding same fields in different cases

Post by Gregory Martin »

Can you give more detail about what you're trying to do? Are you during this during entry or during editing? You can only have one case in memory at a given time, so you may have to be clever with an approach for accessing data from multiple cases.
Bhupender11
Posts: 63
Joined: May 15th, 2018, 1:18 am

Re: Adding same fields in different cases

Post by Bhupender11 »

Dear Gregory Martin,
Thanks for reply.

I have attached a dummy application. Please look into that.
Here are two dictionary file. One is District_Dict and other is Combined_Dict.
I have entered 4 cases in District application where population of men is given.

I want to add total population of men in combined dictionary application.
Attachments
ABC.7z
(3.89 KiB) Downloaded 225 times
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Adding same fields in different cases

Post by Gregory Martin »

You can iterate through each case to total the men:
PROC NO_OF_MENS_COMBINED

preproc

    numeric
total_men = 0;

   
forcase DISTRICT_DICT where STATE_CODE = STATE do
        inc
(total_men, NO_OF_MENS);
   
endfor;

    NO_OF_MENS_COMBINED = total_men;
Bhupender11
Posts: 63
Joined: May 15th, 2018, 1:18 am

Re: Adding same fields in different cases

Post by Bhupender11 »

Thanks
Bhupender11
Posts: 63
Joined: May 15th, 2018, 1:18 am

Re: Adding same fields in different cases

Post by Bhupender11 »

Dear Gregory Martin,

I again stuck there. It shows an error while doing

forcase DISTRICT_DICT where STATE_CODE = STATE do

do numeric ctr = 1 while ctr <= totocc(DISTRICT_REC000)

total_men = (total_men + NO_OF_MENS);
enddo;

total=total+total+men;

endfor;


ERROR: 'DISTRICT_REC000' is not a declared variable or is a misspelled dictionary entry
ERROR: Record, group or multiple item name expected near line 6 in NO_OF_MENS_COMBINED procedure


If the field is multiple than how can I add population of men.


Thanks in advance.
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Adding same fields in different cases

Post by Gregory Martin »

DISTRICT_REC000 likely refers to a roster (form element), which you won't have when using this as an external dictionary. Instead, you'll use the record name, DISTRICT_REC. Also, when you refer to NO_OF_MENS in the loop, you'll want to use NO_OF_MENS(ctr).
Bhupender11
Posts: 63
Joined: May 15th, 2018, 1:18 am

Re: Adding same fields in different cases

Post by Bhupender11 »

I have tried this but it shows Ambiguity error.

Please check.


ERROR: Ambiguous symbol 'DISTRICT_REC' (2 synonyms found) - please provide qualifiers enough to avoid ambiguity near line
Attachments
ABC.7z
(4.27 KiB) Downloaded 190 times
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Adding same fields in different cases

Post by Gregory Martin »

Sometimes you get that error with the totocc function. I like to use the count function instead. This will work:
    forcase DISTRICT_DICT where STATE_CODE = STATE do

        do numeric
ctr = 1 while ctr <= count(DISTRICT_REC)
           
inc(total_men, NO_OF_MENS(ctr));
       
enddo;

   
endfor;
Bhupender11
Posts: 63
Joined: May 15th, 2018, 1:18 am

Re: Adding same fields in different cases

Post by Bhupender11 »

Thanks

It works
Post Reply