Fluorite | Level 6

## How do I make an accumulative variable when two other accumulative values are true?

``````data literacy3;
set ia.literacy;
tot_jaundice + jaundice;
tot_anemia + anemia;
total = 0
if anemia =1 and jaundice = 1
then total = total +1;
keep Subject jaundice tot_jaundice tot_anemia anemia total;
run;``````

This is the code that I ran, and I got a result of

SAS Output

Obs Subject Jaundice Anemia tot_jaundice tot_anemia total
 1 1 1 1 1 . 2 0 1 1 2 . 3 1 1 2 3 . 4 1 1 3 4 . 5 1 1 4 5 . 6 0 1 4 6 . 7 1 1 5 7 . 8 1 1 6 8 . 9 0 0 6 8 . 10 1 1 7 9 . 11 1 1 8 10 . 12 1 1 9 11 . 13 0 1 9 12 . 14 1 1 10 13 . 15 1 0 11 13 . 16 1 1 12 14 . 17 1 1 13 15 . 18 0 1 13 16 . 19 1 1 14 17 . 20 0 0 14 17 . 21 1 1 15 18 . 22 1 1 16 19 . 23 1 1 17 20 . 24 0 1 17 21 . 25 1 1 18 22 . 26 1 1 19 23 . 27 0 1 19 24 . 28 1 1 20 25 . 29 1 1 21 26 . 30 1 1 22 27 . 31 1 1 23 28 . 32 1 1 24 29 . 33 1 1 25 30 . 34 0 0 25 30 . 35 1 1 26 31 . 36 1 1 27 32 . 37 1 1 28 33 . 38 1 1 29 34 . 39 1 1 30 35 . 40 1 1 31 36 . 41 0 0 31 36 . 42 1 1 32 37 . 43 1 1 33 38 . 44 0 0 33 38 . 45 1 1 34 39 . 46 0 1 34 40 . 47 1 1 35 41 . 48 1 0 36 41 . 49 1 1 37 42 . 50 0 0 37 42 .
1 ACCEPTED SOLUTION

Accepted Solutions
Diamond | Level 26

## Re: How do I make an accumulative variable when two other accumulative values are true?

@minsung wrote:

This is an instruction for the problem. Hope it helps

Now create another temporary data set using the same literacy data set. This time create two variables, first an accumulation variable that accumulates the number of subjects that could read the word jaundice. Accumulate a second variable associated with anemia (subjects that could read the word anemia). Make a third variable that accumulate when both are correct. What is the total number of people who could read the two words correctly

Well, I suppose I could get picky and say "accumulate what" when both are correct?

Nevertheless, assuming it means "create the  cumulative count of the number of times both are correct" (does that sound right to you?) then try replacing the line in your program with this corrected line:

``if anemia =1 and jaundice = 1 then total+1;``
--
Paige Miller
4 REPLIES 4
Diamond | Level 26

## Re: How do I make an accumulative variable when two other accumulative values are true?

For us to help you, you would have to explain and show us the desired output.

--
Paige Miller
Fluorite | Level 6

## Re: How do I make an accumulative variable when two other accumulative values are true?

This is an instruction for the problem. Hope it helps

Now create another temporary data set using the same literacy data set. This time create two variables, first an accumulation variable that accumulates the number of subjects that could read the word jaundice. Accumulate a second variable associated with anemia (subjects that could read the word anemia). Make a third variable that accumulate when both are correct. What is the total number of people who could read the two words correctly

Super User

## Re: How do I make an accumulative variable when two other accumulative values are true?

Without actual input example data of your ia.literacy data set I am guessing somewhat. You might want to take a look at the results  of this code.

```proc summary data=ia.literacy;
class anemia jaundice;
output out=literacysummary;
run;```

The output set will have a variable named _freq_ which counts cases of values. There will also be a variable _type_ that indicates which combinations of the class variables are being considered. This will give counts of overall records, possibly not very useful, each level of the variables anemia and jaundice separately and counts of the levels of anemia and jaundice combined. I suspect that _type_ values of 1, 2 and 3 will provide some of the values you want.

Diamond | Level 26

## Re: How do I make an accumulative variable when two other accumulative values are true?

@minsung wrote:

This is an instruction for the problem. Hope it helps

Now create another temporary data set using the same literacy data set. This time create two variables, first an accumulation variable that accumulates the number of subjects that could read the word jaundice. Accumulate a second variable associated with anemia (subjects that could read the word anemia). Make a third variable that accumulate when both are correct. What is the total number of people who could read the two words correctly

Well, I suppose I could get picky and say "accumulate what" when both are correct?

Nevertheless, assuming it means "create the  cumulative count of the number of times both are correct" (does that sound right to you?) then try replacing the line in your program with this corrected line:

``if anemia =1 and jaundice = 1 then total+1;``
--
Paige Miller
Discussion stats
• 4 replies
• 742 views
• 1 like
• 3 in conversation