BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
nab102
Fluorite | Level 6

Hi ,

I want to count the number of people who took a vaccine in a particular year when they have multiple years. This is what I have. 

 

data.PNG

 

 

 So if I want the number of people who took a vaccine in Year 2017, that's going to be 2, that is patient with Id L001 and L005. If a patient took two different vaccines in the same year (for eg. L002), we count it just once (I know that's obvious). This is what I want 

 

want.PNG

 

 

 Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

To count only DISTINCT patients in a given year :

 

proc sql;
create table counts as
select 
    year_of_vaccine,
    count (distinct patient_id) as count
from have0
group by year_of_vaccine;
quit;

proc transpose data=counts out=want(drop=_name_);
var count;
id year_of_vaccine;
run;

PGStats_0-1655575650251.png

 

PG

View solution in original post

2 REPLIES 2
sbxkoenk
SAS Super FREQ

Hello,

 

See here :

data work.have0;
input patient_id $ year_of_vaccine;
cards;
L001 2017
L001 2019 
L002 2020
L002 2020 
L003 2018
L003 2019
L004 2021
L005 2017
L006 2020
L006 2021
;
run;

proc sort data=work.have0 out=work.have1 NODUPKEY;
 by patient_id year_of_vaccine;
run;

PROC FREQ data=work.have1;
 tables year_of_vaccine / out=work.want;
run;
/* end of program */

Koen

PGStats
Opal | Level 21

To count only DISTINCT patients in a given year :

 

proc sql;
create table counts as
select 
    year_of_vaccine,
    count (distinct patient_id) as count
from have0
group by year_of_vaccine;
quit;

proc transpose data=counts out=want(drop=_name_);
var count;
id year_of_vaccine;
run;

PGStats_0-1655575650251.png

 

PG

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 499 views
  • 1 like
  • 3 in conversation