BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Hawkeye
Fluorite | Level 6

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. 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

In one step....

proc means data=sashelp.class stackods q1 q3 qrange maxdec=3;

var age height;

ods output summary=sample_out;

run;

View solution in original post

18 REPLIES 18
PaigeMiller
Diamond | Level 26

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;

--
Paige Miller
Linlin
Lapis Lazuli | Level 10

example:

proc means data = sashelp.class noprint;

var weight height;

    OUTPUT OUT=DATA2 q1= q3= qrange=/autoname  ;

run;

proc print data=data2;run;

Linlin

Hawkeye
Fluorite | Level 6

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.

Linlin
Lapis Lazuli | Level 10

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

Reeza
Super User

In one step....

proc means data=sashelp.class stackods q1 q3 qrange maxdec=3;

var age height;

ods output summary=sample_out;

run;

Linlin
Lapis Lazuli | Level 10

Hi Reeza,

Nice!  Thank you very much!  - Linlin

Hawkeye
Fluorite | Level 6

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.

Linlin
Lapis Lazuli | Level 10

I have sas 9.3, no problem for me to run Reeza's code.

Hawkeye
Fluorite | Level 6

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?

Linlin
Lapis Lazuli | Level 10

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;

Linlin
Lapis Lazuli | Level 10

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

Hawkeye
Fluorite | Level 6

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.

Linlin
Lapis Lazuli | Level 10

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;

Cynthia_sas
SAS Super FREQ

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


compare_tab_method.png

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 18 replies
  • 16814 views
  • 3 likes
  • 7 in conversation