Help using Base SAS procedures

proc means output

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 17
Accepted Solution

proc means output

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. 


Accepted Solutions
Solution
‎07-24-2012 03:49 PM
Grand Advisor
Posts: 16,933

Re: proc means output

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


All Replies
Trusted Advisor
Posts: 1,441

Re: proc means output

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;

Super Contributor
Posts: 1,636

Re: proc means output

example:

proc means data = sashelp.class noprint;

var weight height;

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

run;

proc print data=data2;run;

Linlin

Occasional Contributor
Posts: 17

Re: proc means output

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.

Super Contributor
Posts: 1,636

Re: proc means output

example:

proc means data = sashelp.class noprint;
var age height ;
    OUTPUT OUT=data2(drop=_Smiley Happy q1= q3= qrange=/autoname  ;
run;
data age(rename=(age_q1=q1 age_q3=q3 age_qrange=qrange));
  set data2(keep=ageSmiley Happy;
  item='age';
data height(rename=(height_q1=q1 height_q3=q3 height_qrange=qrange));
  set data2(keep=heightSmiley Happy;
  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

Solution
‎07-24-2012 03:49 PM
Grand Advisor
Posts: 16,933

Re: proc means output

In one step....

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

var age height;

ods output summary=sample_out;

run;

Super Contributor
Posts: 1,636

Re: proc means output

Hi Reeza,

Nice!  Thank you very much!  - Linlin

Occasional Contributor
Posts: 17

Re: proc means output

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.

Super Contributor
Posts: 1,636

Re: proc means output

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

Occasional Contributor
Posts: 17

Re: proc means output

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?

Super Contributor
Posts: 1,636

Re: proc means output

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=ageSmiley Happy;

  item='age';

data height(rename=(height_q1=q1 height_q3=q3 height_qrange=qrange));

  set data2(keep=heightSmiley Happy;

  item='height';

data want;

length item $ 10;

  set age height;

run;

Super Contributor
Posts: 1,636

Re: proc means output

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

Occasional Contributor
Posts: 17

Re: proc means output

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.

Super Contributor
Posts: 1,636

Re: proc means output

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;

SAS Super FREQ
Posts: 8,689

Re: proc means output

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

Attachment
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 18 replies
  • 3084 views
  • 2 likes
  • 7 in conversation