multiple occurring items (BUG)?

Other discussions about CSPro
Forum rules
New release: CSPro 8.0
Post Reply
pierrew
Posts: 47
Joined: August 8th, 2012, 5:20 am
Location: Pohnpei, Federated States of Micronesia

multiple occurring items (BUG)?

Post by pierrew »

Hey all ...
Just curious if you came across this problem.

look at the following code ..

Code: Select all

for i in PERSON do
        // NOT WORKING ....... 
	if AGE(i) in 10:110 then
		tmpCnt1 = 0;
		if count(Q1300000 where Q1304 = "X") > 0 then inc(tmpCnt1); endif;
		if count(Q1300000 where Q1305 = "X") > 0 then inc(tmpCnt1); endif;
		if count(Q1300000 where Q1306 = "X") > 0 then inc(tmpCnt1); endif;
		if count(Q1300000 where Q1307 = "X") > 0 then inc(tmpCnt1); endif;
		if count(Q1300000 where Q1308 = "X") > 0 then inc(tmpCnt1); endif;
		if count(Q1300000 where Q1309 = "X") > 0 then inc(tmpCnt1); endif;
		if count(Q1300000 where Q1310 = "X") > 0 then inc(tmpCnt1); endif;
		if count(Q1300000 where Q1311 = "X") > 0 then inc(tmpCnt1); endif;
		if count(Q1300000 where Q1312 = "X") > 0 then inc(tmpCnt1); endif;
		if count(Q1300000 where Q1313 = "X") > 0 then inc(tmpCnt1); endif;
		if count(Q1300000 where Q1314 = "X") > 0 then inc(tmpCnt1); endif;
		if count(Q1300000 where Q1315 = "X") > 0 then inc(tmpCnt1); endif;
		
		if tmpCnt1 < Q1110(i) then
			addErr(130201,MD1_DATE_I,"Q1300000",i,maketext(130201));
		endif;	
	endif;

	// ALTERNATIVE WORKING VERSION
	if AGE(i) in 10:110 then
		tmpCnt1 = 0;
		tmpCnt2 = 0;
		tmpCnt3 = 0;
		tmpCnt4 = 0;
		tmpCnt5 = 0;
		tmpCnt6 = 0;
		tmpCnt7 = 0;
		tmpCnt8 = 0;
		tmpCnt9 = 0;
		tmpCnt10 = 0;
		tmpCnt11 = 0;
		tmpCnt12 = 0;
		tmpCnt13 = 0;
		
		for j in Q1300000 do
			if Q1304(i,j) = "X" then
				tmpCnt1 = tmpCnt1 + 1;
			endif;
			if Q1305(i,j) = "X" then
				tmpCnt2 = tmpCnt2 + 1;
			endif;
			if Q1306(i,j) = "X" then
				tmpCnt3 = tmpCnt3 + 1;
			endif;
			if Q1307(i,j) = "X" then
				tmpCnt4 = tmpCnt4 + 1;
			endif;
			if Q1308(i,j) = "X" then
				tmpCnt5 = tmpCnt5 + 1;
			endif;
			if Q1309(i,j) = "X" then
				tmpCnt6 = tmpCnt6 + 1;
			endif;
			if Q1310(i,j) = "X" then
				tmpCnt7 = tmpCnt7 + 1;
			endif;
			if Q1311(i,j) = "X" then
				tmpCnt8 = tmpCnt8 + 1;
			endif;
			if Q1312(i,j) = "X" then
				tmpCnt9 = tmpCnt9 + 1;
			endif;
			if Q1313(i,j) = "X" then
				tmpCnt10 = tmpCnt10 + 1;
			endif;
			if Q1314(i,j) = "X" then
				tmpCnt11 = tmpCnt11 + 1;
			endif;
			if Q1315(i,j) = "X" then
				tmpCnt12 = tmpCnt12 + 1;
			endif;
		enddo;
		if tmpCnt1 > 0 then inc(tmpCnt13); endif;
		if tmpCnt2 > 0 then inc(tmpCnt13); endif;
		if tmpCnt3 > 0 then inc(tmpCnt13); endif;
		if tmpCnt4 > 0 then inc(tmpCnt13); endif;
		if tmpCnt5 > 0 then inc(tmpCnt13); endif;
		if tmpCnt6 > 0 then inc(tmpCnt13); endif;
		if tmpCnt7 > 0 then inc(tmpCnt13); endif;
		if tmpCnt8 > 0 then inc(tmpCnt13); endif;
		if tmpCnt9 > 0 then inc(tmpCnt13); endif;
		if tmpCnt10 > 0 then inc(tmpCnt13); endif;
		if tmpCnt11 > 0 then inc(tmpCnt13); endif;
		if tmpCnt12 > 0 then inc(tmpCnt13); endif;

		if tmpCnt13 < Q1110(i) then
			addErr(130201,MD1_DATE_I,"Q1300000",i,maketext(130201));
		endif;	
	endif;
enddo;
OK ... the first set of code is a for a multiple occurring item in a multiple occurring record. The second is for the same multiple occurring item and record. The problem is that the first set screws up the curocc() and the line referencing in a multiple occurring item. So for example AGE(1), if the first routine is enabled, then the results always returns the last occurrence of the item.
DATA ...
AGE
12
15
11
13

RESULT ..
AGE(1) returns 13
AGE(2) returns 13 ... and so on.

The first routine also causes CSPro to return a non-occurrence fault. "Occurrence does not exist"

Let me know if you came across this problem.

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

Re: multiple occurring items (BUG)?

Post by Gregory Martin »

Indeed, you've found a bug when count is used within a for statement that traverses a group. I think that I've fixed the bug, but just to make sure, can you send me your code so I can test it on that: gregory.martin@census.gov.
Post Reply