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;
Is 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.
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;
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;
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.
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.