I am trying to get specific options in my output namely q1 q3 and qrange, however it will only put the standard proc means statistics in my file. Currently my code looks like this
proc means data = data Q1 Q3 qrange/*mean std min max n qrange*/ maxdec = 3;
output out = data2 q1 autoname;
run;
/* Where data is any dataset and data2 is the output.*/
Originally I had tried to output the file as an ods html file but when I tried to re-read in the file it started taking all of the settings of the html file when reading the file.
In one step....
proc means data=sashelp.class stackods q1 q3 qrange maxdec=3;
var age height;
ods output summary=sample_out;
run;
I don't think your output statement syntax is correct.
Something like this ought to work
OUTPUT OUT=DATA2 q1=q1 q3=q3 qrange=qrange;
example:
proc means data = sashelp.class noprint;
var weight height;
OUTPUT OUT=DATA2 q1= q3= qrange=/autoname ;
run;
proc print data=data2;run;
Linlin
Is there anyway that I can get it to look like the output from the proc means statement. It is all in one column right now.
example:
proc means data = sashelp.class noprint;
var age height ;
OUTPUT OUT=data2(drop=_:) q1= q3= qrange=/autoname ;
run;
data age(rename=(age_q1=q1 age_q3=q3 age_qrange=qrange));
set data2(keep=age:);
item='age';
data height(rename=(height_q1=q1 height_q3=q3 height_qrange=qrange));
set data2(keep=height:);
item='height';
data want;
length item $ 10;
set age height;
proc print;run;
Obs item q1 q3 qrange
1 age 12.0 15.0 3
2 height 57.5 66.5 9
In one step....
proc means data=sashelp.class stackods q1 q3 qrange maxdec=3;
var age height;
ods output summary=sample_out;
run;
Hi Reeza,
Nice! Thank you very much! - Linlin
That looks like it may work. I just tried to run what you posted but it said that there was a syntax error with "stackods".
Syntax error, expecting one of the following: ;, (, ALPHA, CHARTYPE, CLASSDATA, CLM, COMPLETETYPES, CSS, CV,
DATA, DESCEND, DESCENDING, DESCENDTYPES, EXCLNPWGT, EXCLNPWGTS, EXCLUSIVE, FW, IDMIN, KURTOSIS, LCLM, MAX,
MAXDEC, MEAN, MEDIAN, MIN, MISSING, MODE, N, NDEC, NMISS, NOLABELS, NONOBS, NOPRINT, NOTHREADS, NOTRAP, NWAY,
ORDER, P1, P10, P25, P5, P50, P75, P90, P95, P99, PCTLDEF, PRINT, PRINTALL, PRINTALLTYPES, PRINTIDS,
PRINTIDVARS, PROBT, Q1, Q3, QMARKERS, QMETHOD, QNTLDEF, QRANGE, RANGE, SKEWNESS, STDDEV, STDERR, SUM, SUMSIZE,
SUMWGT, T, THREADS, UCLM, USS, VAR, VARDEF.
ERROR 202-322: The option or parameter is not recognized and will be ignored.
I have sas 9.3, no problem for me to run Reeza's code.
I have sas 9.2 so maybe that is it? regardless I took out the stackods and it worked.
Edit: I have gotten that output before, but how can I get the variables to fall under each other?
then you have to do some data manipulation. using the code below as an example and changing the RED parts:
data age(rename=(age_q1=q1 age_q3=q3 age_qrange=qrange));
set data2(keep=age:);
item='age';
data height(rename=(height_q1=q1 height_q3=q3 height_qrange=qrange));
set data2(keep=height:);
item='height';
data want;
length item $ 10;
set age height;
run;
with stackods you can get what you want in one step:
proc means data=sashelp.class stackods q1 q3 qrange maxdec=3;
var age height;
ods output summary=sample_out;
run;
proc print;run;
Obs Variable Q1 Q3 QRange
1 Age 12.000 15.000 3.000
2 Height 57.500 66.500 9.000
Yea something like that but really what I am looking for is how can I save the output as .csv file and have it look like the output that is in sas. Currently the way I am doing it is something like this
ods html file = '*filepath*.csv';
proc means data = data Q1 Q3 qrange/*mean std min max n qrange*/ maxdec = 3;
run;
quit;
ods html close;
However when I try to do that it gets exported as a html/csv file that is unable to be imported back into sas. The only way I can get it to work is by running half the program, opening the file in word saving it as a .csv and then continuing the code. What I need is to somehow be able to export the proc means as a .csv file and then reimport it without having to stop the code.
I would create a sas dataset first then create a csv file:
PROC EXPORT DATA= WORK.want
OUTFILE= "C:\TEMP\example.csv"
DBMS=CSV REPLACE;
PUTNAMES=YES;
RUN;
Hi:
You've gotten a lot of good suggestions and if you want to stick with PROC MEANS, then STACKODS is the best solution, but it requires 9.3. So if you would be willing to switch procedures, PROC TABULATE will give you the output you want without manipulating the output dataset or using PROC EXPORT. See the code and results (for HTML and CSV) in the attached screenshot.
cynthia
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.