Hi
I am trying to create a new variable that contains observations that are summed observations from another variable conditional on if the observations fall into a class.
Example:
Class: NAICS
Old variable: employment
New variable: employment_subset
logic to create new variable: employment_subset = sum of employment where NAICS in(21,22,23,..)
I have used proc means to do something similar, e.g. collapse observations by class. Here I want to collapse observations over a specified range categories within a class. Not sure how I would do this either with proc means or in the data step. Can I do this with proc means? If so, how do I condition the collapse over a range of categories within the class?
thanks
try this one:
proc means data= noprint;
var employment;
output out=want ( drop=_: ) sum=employment_subset;
where naics in (21, 22, 23);
run;
Hopefully,it works out.
QLi,
thanks much. what does the option { (drop=_:) } reference after the output out statement? Does this option drop all observations not included in the sum operation?
the option: (drop=_: ) is able to drop the columns (_freq_ , _type_) in the proc means.
You can always use a format as well, this is useful if you want to recategorize variables without really creating a new variable.
*create a format;
proc format;
value age_fmt 12 - 14 = 'Tweens';
run;
*print results;
proc print data=sashelp.class;
format age age_fmt.;
run;
*summarize by the new formats;
proc means data=sashelp.class;
class age; var weight height;
format age age_fmt.;
run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: