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.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 916 views
  • 1 like
  • 3 in conversation