Proc Means - Carry a variable thru to the output ds without alteration

Accepted Solution Solved
Reply
Regular Contributor
Posts: 212
Accepted Solution

Proc Means - Carry a variable thru to the output ds without alteration

I have an additonal variable named pctdenom in my QueryData&ZIP5 ds. I'm wondering if there is a way to pass it thru to the output ds named cal_sum&ZIP5 without altering its value?  I would like it to retain it's value on each record in the output ds.

 

 

	proc means data=QueryData&ZIP5 sum;
	where score_impacting='N' or rule_nm='VOLUME MATCHING';
	var PERCENT total _: null;
	output out=cal_sums&ZIP5 (drop=_type_ _freq_) sum=;
	run;

Accepted Solutions
Solution
‎11-07-2016 04:22 PM
Super User
Posts: 11,134

Re: Proc Means - Carry a variable thru to the output ds without alteration

If the variable has the same value for each record then you could add it to a CLASS statement.

You may need the NWAY option to prevent getting two summaries

proc means data=QueryData&ZIP5 sum nway;
   class pctdenom ;
	where score_impacting='N' or rule_nm='VOLUME MATCHING';
	var PERCENT total _: null;
	output out=cal_sums&ZIP5 (drop=_type_ _freq_) sum=;
	run;

If the variable has multiple values then this would create a summary for each level.

 

View solution in original post


All Replies
Solution
‎11-07-2016 04:22 PM
Super User
Posts: 11,134

Re: Proc Means - Carry a variable thru to the output ds without alteration

If the variable has the same value for each record then you could add it to a CLASS statement.

You may need the NWAY option to prevent getting two summaries

proc means data=QueryData&ZIP5 sum nway;
   class pctdenom ;
	where score_impacting='N' or rule_nm='VOLUME MATCHING';
	var PERCENT total _: null;
	output out=cal_sums&ZIP5 (drop=_type_ _freq_) sum=;
	run;

If the variable has multiple values then this would create a summary for each level.

 

Regular Contributor
Posts: 212

Re: Proc Means - Carry a variable thru to the output ds without alteration

Perfect. Thanks so much for taking the time to help!
Super User
Posts: 5,368

Re: Proc Means - Carry a variable thru to the output ds without alteration

I'm not sure if you are picturing the result properly.  Are you aware that the output data set contains just 1 observation?

Super User
Posts: 11,134

Re: Proc Means - Carry a variable thru to the output ds without alteration


Astounding wrote:

I'm not sure if you are picturing the result properly.  Are you aware that the output data set contains just 1 observation?


Was that question for me? Yes, I realize the OP output only has one record. But I am not going to assume the the input has only one value for another variable wanted. I realize it makes sense that there could be only one value but how often do we see not well stated or constrained questions? So I provided one possible solution that would be easy to implement if the data is clean and a warning that the method will not do what was requested if there is an issue with the variable.

 

 

Super User
Posts: 5,368

Re: Proc Means - Carry a variable thru to the output ds without alteration

ballardw,

 

No, the question was for the original poster.  You correctly figured out that there was only one observation in the output now, but the objective was to split up the results into multiple observations.  I wasn't sure, so I figured I would ask ... perhaps not using the best choice of words in retrospect.

 

Also note, the ID statement could be useful here to avoid the NWAY complications.

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 214 views
  • 0 likes
  • 3 in conversation