BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
peer
Calcite | Level 5

proc freq data=x nlevels;

table patient_id;

run;

I am trying to count the # of unique patients in this data.

Does the resulting output show the number of unique patient ids? or just the total amount of observations with non-missing ids.

Thank you, I appreciate the help.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If you need count of unique IDS:

proc sql:

     select count(*)

     from (select DISTINCT patient_id from x);

quit;

If you need list of unique ids:

proc sql;

     select distinct Patient_id

     from x;

quit;

View solution in original post

5 REPLIES 5
stat_sas
Ammonite | Level 13

It will provide total number of observations for each level of patient_id. So if each patient_id has one frequency then we can conclude that patient_id is unique.

Reeza
Super User

Not quite, NLEVELS does produce the number of distinct observations in the number of levels table.

Be careful of how it treats missing and how you want missing values treated though.

proc freq data=sashelp.class nlevels;

table age;

run;

ballardw
Super User

If you need count of unique IDS:

proc sql:

     select count(*)

     from (select DISTINCT patient_id from x);

quit;

If you need list of unique ids:

proc sql;

     select distinct Patient_id

     from x;

quit;

AaronDavid
Calcite | Level 5

To answer your question OP, the nlevels option will count distinct values, including missing values. The following code can help you break down multiple variables into unique values missing and non-missings much easier than performing the same task with a proc sql:

 

ods output nlevels=LEVELS;
proc freq data=dataset nlevels;
tables var1 var2 var3 var4 / noprint ;
run;
proc print data=LEVELS;
run;

sas-innovate-2024.png

Today is the last day to save with the early bird rate! Register today for just $695 - $100 off the standard rate.

 

Plus, pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 20143 views
  • 7 likes
  • 5 in conversation