Sum within a roster with a skip

Discussions about CSEntry
Post Reply
Anysia

Sum within a roster with a skip

Post by Anysia »

I have a roster with size 20 with purchases of households items and amount.
the list is applicable to all households on their weekly households expenditure.
want to use row (occurrence) 21 as Total amount spent in a week. TThe following are in the roster
HEID Item Description Quantity
1.
2.
3.
21(Total)
I used the following codes to sum the roster for HHID 6
numeric x6a;
x6a = s5a1 + s5a2 + s5a3 + s5a4 + s5a5

if curocc(SEC5A000) = 6 then
if not $(6)= x6a then
errmsg("Check Total. System calculated is %d and What you keyed is %d",x6a,$(6));
reenter
endif;
endif;
The above codes works well. But my challenge is not all households provided for all HEID (6) items thus a keyer have to key zero (0)
throughout even if the household consume an item for the above checks to work. To resolve this issue i introduced this codes

If S5aID in 1:5 and S5A(S5aID) = " " then
skip to HEID(6);
endif;

After it skips all right but my total check does not work again, rather an error message pop up that NOTApp is expected.
Where should introduce the NOTAPP in my codes
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Sum within a roster with a skip

Post by josh »

When you have a skipped (blank) numeric value in CSPro the system assigns it the special value NOTAPPL. When you sum a group of values that includes a NOTAPPL value the sum also becomes NOTAPPL. You should exclude the NOTAPPL values. You can write the logic as follows:
x6a = 0;
if s5a1 <> notappl then
  x6a = x6a + s5a1;
endif;
if s5a2 <> notappl then
  x6a = x6a + s5a2;
endif;
etc...
Saint
Posts: 63
Joined: November 22nd, 2013, 4:59 am

Re: Sum within a roster with a skip

Post by Saint »

In the past, I will define a function like this in proc global:
function av(var)
if var=missing or var=notappl then
av = 0;
else
av = val;
endif;
end;

Then in such functions, you can write x6a=av(s5a1)+av(s5a2)...
In this case, it does not matter if any of the s5a variables is skipped or missing.
Anysia
Posts: 28
Joined: March 12th, 2016, 6:54 am

Re: Sum within a roster with a skip

Post by Anysia »

Please i still have a challenge in summing in my roster, i have then attached my application
for help.
Thanks in advance.
Attachments
weekExpense2015.zip
Sum within a roster
(4.95 KiB) Downloaded 310 times
Saint
Posts: 63
Joined: November 22nd, 2013, 4:59 am

Re: Sum within a roster with a skip

Post by Saint »

Please try the attached and see if it works for you as expected. Best.
Attachments
weekExpense2015.zip
(5.51 KiB) Downloaded 344 times
Anysia
Posts: 28
Joined: March 12th, 2016, 6:54 am

Re: Sum within a roster with a skip

Post by Anysia »

Thanks so much Saint. A quick one again.
I want to apply same logic in your function but this time around i have 100 roster occurrence, It cumbersome using
the plus (+) for all occurrence.Doing this for 100 rows ...( x5b = av(W1B(1)) + av(W1B(2)) + av(W1B(3)) + av(W1B(4)) + av(W1B(5));
I tried the sum function and am fighting with errors..

I have attached the program and expanded the occurrence to 100.

Thanks in advance.
Attachments
weekExpense2015.zip
App
(5.88 KiB) Downloaded 292 times
Saint
Posts: 63
Joined: November 22nd, 2013, 4:59 am

Re: Sum within a roster with a skip

Post by Saint »

Hi Anysia,
Find attached the revised program that simplifies what you want to do.

Best.
Attachments
weekExpense2015.zip
(6.43 KiB) Downloaded 377 times
Post Reply