Help using Base SAS procedures

Proc Means: "output window" not the same as "output" option

Reply
Contributor
Posts: 58

Proc Means: "output window" not the same as "output" option

Ok, so when i run the following code
[pre] proc means data=_9SSummary sum maxdec=0;
var _:;
output out=_9SSummaryA sum=Outs_Hits_Errors n=number;
run;[/pre]

the output window gives me what i want: the sum of eacch variable; however, the output data set "_9SSummaryA" then gives the sum of the first variable only.

Help?
Valued Guide
Posts: 632

Re: Proc Means: "output window" not the same as "output" option

Try using the autoname option on the OUTPUT statement. It makes life a whole lot easier.
[pre]proc means data=sashelp.class sum;
var height weight;
output out=totals
sum=/autoname;
run;[/pre]
Contributor
Posts: 58

Re: Proc Means: "output window" not the same as "output" option

Thanks. Any idea how i would then get the variable names back to the original names?
Frequent Contributor
Posts: 106

Re: Proc Means: "output window" not the same as "output" option

If by 'original name' you mean the name assigned by you then code the output statement somewhat like
[pre]
output out=_9SSummaryA
sum(var1)=outvar_name1
sum(var2)=outvar_name2
sum(var3)=outvar_name3
n=number;
[/pre]
Respected Advisor
Posts: 3,777

Re: Proc Means: "output window" not the same as "output" option

The procedure will name the stats with original names when you use stat= with no variable names following. However when you want two statistics you will end up needing autoname, and you're right back where you started.

I prefer the arrangement of the default data set but you can only get a few statistics and SUM ain't one of them. You might try this.

[pre]
proc means noprint data=sashelp.class;
class sex;
output out=sum sum=;
output out=n n=;
run;
data stats;
set sum(in=in1) n(in=in2);
by _type_ sex;
length _STAT_ $8;
select;
when(in1) _stat_ ='SUM';
when(in2) _stat_ ='N';
end;
run;
proc print data=stats;
run;
[/pre]

You have to be careful if you want CLM's. See
http://tinyurl.com/235pytp

http://www.sascommunity.org/wiki/Adding_statistics_to_the_PROC_MEANS/SUMMARY_default_output_dataset.

for details.

It would be so nice if SAS would just output the default data set with any statistics named in the proc statement.
Valued Guide
Posts: 2,174

Re: Proc Means: "output window" not the same as "output" option

Charles

your OUTPUT statement requested statistics SUM and N. My output window from PROC MEANS didn't show the N statistic because you put SUM in the proc means statement but not N, so I'm a little confused which is what you wanted.
So with nothing else to go on, I'll assume both.
I generated this test data[pre]data _9SSummary ;
do _1 = 1 to 3 ;
do _2 = 2 to 4 by 2 ;
do _3 = 3 to 9 by 3 ;
_4= (_1*10 +_2 )*10 +_3 ;
if not mod( _4, 7 ) then _4=. ; ;
output ;
end; end; end;
stop ;
run ;[/pre]***** I wanted to have an analysis variable occasionally missing;

When you need only one statistic (say, SUM), PROC MEANS is your best friend
proc means data= _9SSummary nway ;
var _: ;
output sum= out= _9SSummaryA( drop= _type_ _freq_ ) ;
rurn ;
Then PROC MEANS assumes that the statistics should be named like the original variables from which they are derived.
You can even leave out that VAR statement and PROC MEANS will provide the statistics for all numeric variables when that is what you need.
There is another excellent feature in PROC MEANS ----> more than one OUTPUT statement can be used.
So, if you really needed two statistics - create a separate output for each stat.
OUTPUT OUT= stat1 SUM= ;
OUTPUT OUT= stat2 N= ;
Of course you will want to bring the results back together again - how about[pre]proc means data=_9SSummary n sum maxdec= 0;
var _: ;
output out=_9SSummaryS sum= ;
output out=_9SSummaryN n= ;
run;
data together ;
set _9SSummaryN(in= stat2)
_9SSummaryS(in= stat1) ;
drop _type_ _freq_ ;
if stat1 then _stat_ = 'SUM' ;else _stat_ ='N' ;
run ;
proc transpose out= _9SSummaryA( rename= _name_= Variable) ;
id _stat_ ;
run ;
proc print ;
run ; [/pre]From my brief test data, I got this listing[pre]
Obs Variable N SUM

1 _1 18 36
2 _2 18 54
3 _3 18 108
4 _4 15 3450
[/pre]
So Charles, what was it you wanted?

peterC looks like I type too slowly ! data _null_; seems to have made my suggestions redundant ;-(


Message was edited by: Peter.C
Respected Advisor
Posts: 3,777

Re: Proc Means: "output window" not the same as "output" option

> looks like I type too slowly ! data _null_; seems to
> have made my suggestions redundant ;-(

Perhaps not. I did not flip to rows to vars with stats as columns.

> proc transpose out= _9SSummaryA( rename= _name_= Variable) ;

PROC TRANSPOSE has an option to change the name of _NAME_, NAME=. Slightly less fiddly than the RENAME data set option.
Ask a Question
Discussion stats
  • 6 replies
  • 162 views
  • 0 likes
  • 5 in conversation