BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Reeza
Super User
It’s not a huge deal, but you should probably mark one of Tom’s answer as correct, he provided more help and better answers than I did here :).
jessica_join
Obsidian | Level 7

Ooops thank you. I thought it was Toms post. Thank you for your help as well!

Tom
Super User Tom
Super User

Now that you have made some progress perhaps you can explain in more detail the overall picture. 

 

Looking at your final program and the 15 sample records you posted it looks like you really only have TWO variables in your source table. The SYMPTOM and SYMPTOM_NO fields have the same information.  When SYMPTOM_NO=1 then SYMPTOM is always equal to "Heartburns". 

data have ;
 infile cards truncover ;
 input id_no symptom_no symptom $20. ;
cards;
1 1 Heartburns
1 2 Sickness
4 5 Tiredness
6 1 Heartburns
7 4 Temperature
8 1 Heartburns
8 5 Tiredness
9 2 Sickness
9 3 Spasm
9 4 Temperature
10 3 Spasm
10 5 Tiredness
11 3 Spasm
11 5 Tiredness
12 4 Temperature
12 5 Tiredness
13 3 Spasm
13 4 Temperature
14 3 Spasm
15 1 Heartburns
;

So what is it that you want to calculate in the data step?  Do you want to count how many times a given ID got a particular symptom? Perhaps you want to use the symptom names as the variable names in your array?   Also what is this DISEASE variable you mentioned?  Is that something you are supposed to calculate?  Is it the count of how many records each ID had?

 

Perhaps you want something like this?

This is an example of what is called a DOW loop.  It eliminates the need for retaining variables or an OUTPUT statement since it processes all of the records for a given BY group in the same iteration of the data step.

data want ;
  do until (last.id_no);
    set have ;
    by id_no;
    array counts Heartburns Sickness Spasm Temperature Tiredness ;
    if first.id_no then do _n_=1 to dim(counts);
       counts(_n_)=0;
    end;
    counts(symptom_no)=counts(symptom_no)+1;
    disease=sum(disease,1);
  end;
  keep id_no Heartburns Sickness Spasm Temperature Tiredness Disease ;
run;

image.png

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 17 replies
  • 3814 views
  • 5 likes
  • 4 in conversation