BookmarkSubscribeRSS Feed
jasmineburbank
Calcite | Level 5

Hello,

In my dataset each person (eventID) is associated with 1-3 pathogens (pathogenSeq). I want to look at the total counts of each of the pathogens, but some people have tested with more than 1 pathogen. How would I make it so that if a person has multiple pathogens they are counted for each pathogen? 

Here is what I tried per my teacher's advice but the output is blank: 

proc sort data=infection;
by eventID pathogenSeq; run;

data infection2;
set infection;
if first.pathogenSeq = 1 then count = 0;
count = count + 1;
if last.pathogenSeq = 1 then output;
retain count; run;

Would it make more sense to create a new variable for pathogen? Any help is appreciated, thanks!

3 REPLIES 3
Astounding
PROC Star
To get started, insert the missing statement. Following the SET statement, repeat the BY statement exactly as it appears in the PROC SORT step.
jasmineburbank
Calcite | Level 5

I added a BY statement and did not receive any error messages.

How would you recommend I verify the procedure worked properly?

andreas_lds
Jade | Level 19

Maybe:

proc summary data=have nway;
  class pathogenSeq;
  output out=counted(drop= _type_ rename=(_freq_ = count));
run;

If this doesn't work, please post example data in usable form together with the expected result.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 309 views
  • 1 like
  • 3 in conversation