BookmarkSubscribeRSS Feed
CharlesR
Calcite | Level 5
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?
6 REPLIES 6
ArtC
Rhodochrosite | Level 12
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]
CharlesR
Calcite | Level 5
Thanks. Any idea how i would then get the variable names back to the original names?
Robert_Bardos
Fluorite | Level 6
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]
data_null__
Jade | Level 19
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.
Peter_C
Rhodochrosite | Level 12
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
data_null__
Jade | Level 19
> 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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 902 views
  • 0 likes
  • 5 in conversation