Fluorite | Level 6

Creating a accumulate totals

``````proc contents data = ia.literacy;
run;
proc sort data=ia.literacy out=sort_literacy;
by Subject;
run;
data ia.literacy2;
set ia.literacy;
tot_jaundice + jaundice;
keep Subject id jaundice tot_jaundice;
run;``````

WARNING: The variable id in the DROP, KEEP, or RENAME list has never been referenced.
NOTE: There were 50 observations read from the data set IA.LITERACY.
NOTE: The data set IA.LITERACY2 has 50 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

This is instruction that I got

a. Use the literacy data set. Run proc contents and see what variables are in the data set. Sort the data by Subject number.

b. Determine the number of subjects that correctly read the word jaundice by creating an accumulation variable. The variable jaundice will have the value of 1 for these subjects if correct, 0 otherwise. Create a temporary dataset and keep just the Subject id, jaundice and the accumulation variable that you create. Use proc means to check that the last observations is the sum of the jaundice variable.

and I have trouble with solving b.

could you help me with this please?

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Tourmaline | Level 20

Re: Creating a accumulate totals

The data step should be

``````data ia.literacy2;
set ia.literacy;
tot_jaundice + jaundice;
keep Subject jaundice tot_jaundice;
run;``````
3 REPLIES 3
Tourmaline | Level 20

Re: Creating a accumulate totals

The data step should be

``````data ia.literacy2;
set ia.literacy;
tot_jaundice + jaundice;
keep Subject jaundice tot_jaundice;
run;``````
Ammonite | Level 13

Re: Creating a accumulate totals

``````proc contents data = ia.literacy;
run;
proc sort data=ia.literacy out=sort_literacy;
by Subject;
run;
data ia.literacy2(keep Subject id jaundice tot_jaundice);
set ia.literacy;

by subject;
if first.subject then tot_jaundice =0;
tot_jaundice + jaundice;
if last.subject then output;

run;``````

Ammonite | Level 13

Re: Creating a accumulate totals

``````data ia.literacy2;

retain tot_jaundice 0;
set ia.literacy;

by subject;

if first.subject then tot_jaunice = 0;
tot_jaundice + jaundice;

if last.subject then output;
keep Subject id jaundice tot_jaundice;
run;``````
Discussion stats
• 3 replies
• 1274 views
• 1 like
• 3 in conversation