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

I am counting number of subjects of screened and screen failure and need to condition them based on condition

proc sql;
    create table scrnd as
     select count(SUBJID) as screened

     where term="SCREENED" from subjd;

     

      create table scrfail as
     select count(SUBJID) as scrnfail

     where term="SCRNFAIL" from subjd;

quit;

 

Is there any precise way to do only in one create statement to get rid of set later?

1 ACCEPTED SOLUTION

Accepted Solutions
4 REPLIES 4
vraj1
Quartz | Level 8

I am making a table of various counts of patients and wondering if there is any smarter way in doing in single create statement

Kurt_Bremser
Super User

Use proc freq for that:

data have;
input subjid term $;
cards;
1 SCREENED
2 SCREENED
3 SCRNFAIL
4 SCREENED
5 SCRNFAIL
;
run;

proc freq data=have;
tables term / out=want;
run;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

There are numerous options, as @Kurt_Bremser proc freq is the simplest.  You could also use union:

proc sql;
    create table scrnd as
    select count(SUBJID) as screened  
    from subjd
    where term="SCREENED"
    union all
    select count(SUBJID) as scrnfail
    from subjd
    where term="SCRNFAIL"; 
quit;

Or use a datastep and retain counts.  To be honest your question is pretty vague.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 4 replies
  • 732 views
  • 1 like
  • 3 in conversation