BookmarkSubscribeRSS Feed
cdubs
Quartz | Level 8

Hi all,

 

I'm trying to create a summary of the overall_days variable, and also giving a proportion of observations where overall_days are above 360 and 730. But the syntax doesn't seem to work quite right... wondering if there's a way around this? Thank you!

 

proc sql;
			create table summary as
			select 	min(overall_days) as min,
					max (overall_days) as max,
					mean (overall_days) as mean,
					median (overall_days) as median

count(enrolid) where overall_days>730 / count(enrolid) as proportion_730,
count(enrolid) where overall_days>365 / count(enrolid) as proportion_365

			from temp.base;
		quit;
1 REPLY 1
Reeza
Super User

Yeah, you can't apply WHERE like that within a statement. But you can use the conditional logic trick to get it. 

 

SAS evaluates boolean conditions to 0/1, and then you can sum the 1's to get the number you need. 

Overall_Days>730 -> resolves to 0/1 for each record. 

Counting it would still give you the total N, but SUM would add up all the 1's. 

 

You could also use a subquery and CASE statements but this seems easier IMO.

 

sum(overall_days>730) / count(enrolid) as proportion_730

 


@cdubs wrote:

Hi all,

 

I'm trying to create a summary of the overall_days variable, and also giving a proportion of observations where overall_days are above 360 and 730. But the syntax doesn't seem to work quite right... wondering if there's a way around this? Thank you!

 

proc sql;
			create table summary as
			select 	min(overall_days) as min,
					max (overall_days) as max,
					mean (overall_days) as mean,
					median (overall_days) as median

count(enrolid) where overall_days>730 / count(enrolid) as proportion_730,
count(enrolid) where overall_days>365 / count(enrolid) as proportion_365

			from temp.base;
		quit;

 

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!

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
  • 1 reply
  • 1057 views
  • 1 like
  • 2 in conversation