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

I'd like to get the median, and IQR, of a continuous variable using PROC SURVEYMEANS. I can't seem to figure out the syntax. Neither "50" nor "median" seems to work.

PROC SURVEYMEANS DATA=&dataset PLOTS=histogram PERCENTILE=50;
 	STRATUM sdmvstra;
 	CLUSTER sdmvpsu;
 	WEIGHT &weight;
 	
	VAR 
/* 	DEMOGRAPHICS; */
	age_yrs
	;
RUN;

Screenshot 2022-11-02 at 4.21.04 PM.pngIs there a

Also, is there a way to add a normality test, like Shapiro-Wilk? 

 

Is there a PROC SURVEYUNIVARIATE? Doesn't seem like it...

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
PharmlyDoc
Quartz | Level 8

The proc surveymeans statement has a range option, but not IQR – SAS must have a reason why. 

I suppose you could manually subtract Q1 from Q3. 

 

proc surveymeans data=CBECS_2003 quartiles mean ;
  strata STRATUM8;
  cluster PAIR8;
  var ELEXP8;
weight ADJWT8;
ods output 
Quantiles=Quantiles;
run;

proc transpose data=quantiles name=Quantile prefix=Quantile out=Quantiles2;
var Estimate;
run;

proc sql;
select
Quantile3-Quantile1 as IQR
from Quantiles2;
quit;

View solution in original post

3 REPLIES 3
PharmlyDoc
Quartz | Level 8

Use  "percentile=(50)"

 

Or just type "quartiles" in the proc surveymeans statement. 

 

For example: 

 

/*  https://www.eia.gov/consumption/commercial/data/2003/index.php?view=microdata
File 15 */

filename csvFile url "https://www.eia.gov/consumption/commercial/data/2003/csv/FILE15.csv" termstr=crlf; 
 
proc import datafile=csvFile  
dbms=csv  
out=CBECS_2003; 
getnames=yes; 
guessingrows=3000; 
run; 

proc surveymeans data=CBECS_2003 quartiles /* percentile=(50) */ mean;
  strata STRATUM8;
  cluster PAIR8;
  var ELEXP8;
weight ADJWT8;
run;

Screen Shot 2022-11-02 at 7.41.03 PM.png

 

_maldini_
Barite | Level 11

Sorry, I should have been more clear...I want the median and IQR in addition to the mean. I basically want something that looks like PROC Univariate output so I can assess for normality of the distribution of the continuous variables.

PharmlyDoc
Quartz | Level 8

The proc surveymeans statement has a range option, but not IQR – SAS must have a reason why. 

I suppose you could manually subtract Q1 from Q3. 

 

proc surveymeans data=CBECS_2003 quartiles mean ;
  strata STRATUM8;
  cluster PAIR8;
  var ELEXP8;
weight ADJWT8;
ods output 
Quantiles=Quantiles;
run;

proc transpose data=quantiles name=Quantile prefix=Quantile out=Quantiles2;
var Estimate;
run;

proc sql;
select
Quantile3-Quantile1 as IQR
from Quantiles2;
quit;
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
  • 1945 views
  • 6 likes
  • 2 in conversation