BookmarkSubscribeRSS Feed
jdub
Calcite | Level 5

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 

4 REPLIES 4
QLi
Fluorite | Level 6 QLi
Fluorite | Level 6

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.

jdub
Calcite | Level 5

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?

QLi
Fluorite | Level 6 QLi
Fluorite | Level 6

the option:  (drop=_: )  is able to drop the columns (_freq_ , _type_)  in the proc means.

Reeza
Super User

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1627 views
  • 0 likes
  • 3 in conversation