turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Proc Means: "output window" not the same as "outpu...

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-17-2010 01:15 AM

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?

[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?

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to CharlesR

08-17-2010 01:43 AM

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]

[pre]proc means data=sashelp.class sum;

var height weight;

output out=totals

sum=/autoname;

run;[/pre]

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to ArtC

08-17-2010 02:46 AM

Thanks. Any idea how i would then get the variable names back to the original names?

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to CharlesR

08-17-2010 05:03 AM

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]

[pre]

output out=_9SSummaryA

sum(var1)=outvar_name1

sum(var2)=outvar_name2

sum(var3)=outvar_name3

n=number;

[/pre]

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to CharlesR

08-17-2010 08:41 AM

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.

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.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to CharlesR

08-17-2010 09:12 AM

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

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

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Peter_C

08-17-2010 09:40 AM

> 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.

> 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.