Help using Base SAS procedures

Creating new variable using proc means

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Creating new variable using proc means

Hello.  I have a data set with person-level wage data.  Each person's record also includes a state, month, and year variable.

 

I would like to be able to generate the median wage for each state in a given month and then create a new variable with that value. 

 

Is there a way to do this directly via code and avoid copying from the output window?

 

I am using SAS 9.3.

 

Thank you for any help you can provide.


Accepted Solutions
Solution
‎07-26-2017 05:34 PM
Super User
Posts: 19,770

Re: Creating new variable using proc means

[ Edited ]

https://github.com/statgeek/SAS-Tutorials/blob/master/proc_means_basic

 

Yes, PROC MEANS has an OUTPUT statement that allows you to capture the output data. 

You may need to tweak the BY statement to get exactly what you want but the follow should help you get started.

 

proc means data=have noprint;
BY STATE YEAR MONTH;
var wage;
output out=want median(wage) = median_wage;
run;

 


Mica27 wrote:

Hello.  I have a data set with person-level wage data.  Each person's record also includes a state, month, and year variable.

 

I would like to be able to generate the median wage for each state in a given month and then create a new variable with that value. 

 

Is there a way to do this directly via code and avoid copying from the output window?

 

I am using SAS 9.3.

 

Thank you for any help you can provide.


 

View solution in original post


All Replies
PROC Star
Posts: 325

Re: Creating new variable using proc means

you can do this by doing output statement. I have copied an example for you for below link

http://www2.sas.com/proceedings/sugi29/240-29.pdf

 

PROC MEANS DATA=SUGI.ELEC_ANNUAL NOPRINT;
VAR TOTREV TOTKWH TOTHRS;
OUTPUT OUT=SUGI2 sum(TOTREV TOTKWH) = sum_rev sum_kwh
mean(TOTREV) = mean_rev
median(TOTHRS) = median_hrs;
run;
New Contributor
Posts: 3

Re: Creating new variable using proc means

Thank you very much!  I will try this out.

New Contributor
Posts: 3

Re: Creating new variable using proc means

Thanks for your help.
Solution
‎07-26-2017 05:34 PM
Super User
Posts: 19,770

Re: Creating new variable using proc means

[ Edited ]

https://github.com/statgeek/SAS-Tutorials/blob/master/proc_means_basic

 

Yes, PROC MEANS has an OUTPUT statement that allows you to capture the output data. 

You may need to tweak the BY statement to get exactly what you want but the follow should help you get started.

 

proc means data=have noprint;
BY STATE YEAR MONTH;
var wage;
output out=want median(wage) = median_wage;
run;

 


Mica27 wrote:

Hello.  I have a data set with person-level wage data.  Each person's record also includes a state, month, and year variable.

 

I would like to be able to generate the median wage for each state in a given month and then create a new variable with that value. 

 

Is there a way to do this directly via code and avoid copying from the output window?

 

I am using SAS 9.3.

 

Thank you for any help you can provide.


 

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 334 views
  • 1 like
  • 3 in conversation