DATA Step, Macro, Functions and more

Proc means for a list of variables start with _

Accepted Solution Solved
Reply
Super Contributor
Posts: 412
Accepted Solution

Proc means for a list of variables start with _

Hi,

I want to run a proc means for a list of variables that start with _

 

	proc means data=PL noprint;
	var _:;
	by type;
	output out=PL_sum
	sum= _:;
	run;

The problem is with SUM=_:

Is there any way to let SAS keep the original name for variable in output file?

Thank you,

HC

 


Accepted Solutions
Solution
‎06-07-2017 02:51 PM
Super User
Posts: 19,815

Re: Proc means for a list of variables start with _

You don't need that. Your original code was correct, you just needed to not list any variables in the SUM statement, since you'd already done so in the VAR statement.

proc means data=class SUM noprint;
	by sex;
	var weight height age;
	output out=want sum=;
run;

proc print data=want;
run;

View solution in original post


All Replies
Super User
Posts: 19,815

Re: Proc means for a list of variables start with _

1. Check if the ODS tables work better for you. 

2. There is the AUTONAME option but it ends up being the variable_statistic type format. It may work for you, but it isn't the original variable name.

Super Contributor
Posts: 412

Re: Proc means for a list of variables start with _

Thanks,

 

I use that ODS and Transpose to get what I want.

 

However, there is a minor issue related to the number format.

 

In the TEMP_ file, some numbers are 2 decimal place, some are rounded.

 

Is there anyway to choose the format of the number in the TEMP_File?

 

Thanks

 

HC

 


ods listing close;
ods output summary=TEMP_;
proc means data=PL stackods SUM;
	by Type;
run;
ods output close;
ods listing;
run;

proc transpose data=TEMP_ out=WANT ;
by Type;
var sum;
id variable;
run;
Super User
Posts: 19,815

Re: Proc means for a list of variables start with _

Apply a format to the new variables. Most likely the underlying variables have the decimal values as well. 

 

Usually you use STACKODS and don't transpose or don't use STACKODS. 

Did not using STACKODS give you what you want directly?

Super Contributor
Posts: 412

Re: Proc means for a list of variables start with _

Nice, No stackods is better.
But the name ending with _sum, which is understandable.
Is there any way to get rid of that _SUM all together? It is not efficient to write 30 rename.

HC
PROC Star
Posts: 1,760

Re: Proc means for a list of variables start with _

What's wrong with

 


proc means data=PL(keep=TYPE _:) noprint;
  by TYPE;
  output out=SUM sum=;
run;
Super Contributor
Posts: 412

Re: Proc means for a list of variables start with _

Thanks a lot for your helps.

HHC

Solution
‎06-07-2017 02:51 PM
Super User
Posts: 19,815

Re: Proc means for a list of variables start with _

You don't need that. Your original code was correct, you just needed to not list any variables in the SUM statement, since you'd already done so in the VAR statement.

proc means data=class SUM noprint;
	by sex;
	var weight height age;
	output out=want sum=;
run;

proc print data=want;
run;
☑ This topic is solved.

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

Discussion stats
  • 7 replies
  • 162 views
  • 1 like
  • 3 in conversation