DATA Step, Macro, Functions and more

Values of 'Proc Mean' into dataset

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 143
Accepted Solution

Values of 'Proc Mean' into dataset

Hi all,

 

I have the following code:

proc means data=sample5 mean std;
	var fare;
	output out=sampleX5;
run; 

I received the following output:

1.jpg

On the same time I badly need to prepare the following output:

 

-----------------------------------------------

Sample No | Seed No | Mean | Std |

-----------------------------------------------

                  |                 |            |       |

------------------------------------------------

 

Is it possible to use any options in mean function to sort it out? Or should I use 'proc transpose' only? Thank you.


Accepted Solutions
Solution
‎08-30-2017 02:30 AM
Frequent Contributor
Posts: 143

Re: Values of 'Proc Mean' into dataset

Posted in reply to DmytroYermak

Hi all,

 

Here it is the desicion using the link provided by Reeza.

 

proc means data=sample&i noprint;
			var fare;
			output out=sampleX&i(drop=_type_ _freq_) mean= std= / autoname;
		run; 

		data sampleY&i;
			length sample_no $2 seed_no $5;
			set sampleX&i;
				sample_no=&i;
				seed_no=&&seed&i;
		run;

View solution in original post


All Replies
Super User
Posts: 19,878

Re: Values of 'Proc Mean' into dataset

Posted in reply to DmytroYermak

STACKODS option in your PROC MEAN statement and then use the ODS Table.

 

http://blogs.sas.com/content/sgf/2015/07/17/customizing-output-from-proc-means/

 

See the last section of the blog post.

Frequent Contributor
Posts: 143

Re: Values of 'Proc Mean' into dataset

Thank you, Reeza. It seems that it will take some time to be familiarized with 'STACKODS'. I used you link in my decision. It is following.
Super User
Posts: 11,343

Re: Values of 'Proc Mean' into dataset

Posted in reply to DmytroYermak

Perhaps something like:

proc summary data=sample5 nway ;
   class sample seed;
var fare; output out=sampleX5 mean= std= /autoname; run;

You don't provide any variable names in your example that correspond to "sample no" or "seed" so I'm guessing here.

 

Proc summary does everything that means does with minor differences in some default behaviors. Summary always expects to build an output data set (ancient history Means didn't and summary was it) and will attempt to have statistics in columns not rows however you need to provide output names or use the autoname option which will, in this example, create fare_mean and fare_std. If you have multiple variables with the same requested statistics the basevariable receives a suffix with the statistic to create unique variables.

Solution
‎08-30-2017 02:30 AM
Frequent Contributor
Posts: 143

Re: Values of 'Proc Mean' into dataset

Posted in reply to DmytroYermak

Hi all,

 

Here it is the desicion using the link provided by Reeza.

 

proc means data=sample&i noprint;
			var fare;
			output out=sampleX&i(drop=_type_ _freq_) mean= std= / autoname;
		run; 

		data sampleY&i;
			length sample_no $2 seed_no $5;
			set sampleX&i;
				sample_no=&i;
				seed_no=&&seed&i;
		run;
Super User
Posts: 19,878

Re: Values of 'Proc Mean' into dataset

Posted in reply to DmytroYermak

This is a great example of why you should have used a single seed and REP. Then you can just use the BY statement. I think it's still worth stacking them and then processing.

 

*stack data together;
data have;
set seed1-seed10 indsname=source;
file=source;
run;

*sort to allow for BY. Could do CLASS as well;
proc sort data=have; by file;

proc means data=have nway stackods mean std;
by file;
var fare;
ods output summary=want;
run;

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

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

Discussion stats
  • 5 replies
  • 97 views
  • 5 likes
  • 3 in conversation