- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;