BookmarkSubscribeRSS Feed
evat
Calcite | Level 5

Hi! I'm a long-time stata user and new to sas. I'm trying to figure out how to create a new variable based on the sum of the values of another variable.

 

In stata, I can do this using the "egen" command. For example,

 

gen CSI1strong = 1 if csi1>5 

egen csi1strong=sum(CSI1strong), by(survey) 

 

The first line of code creates a new variable, CSI1strong, that is equal to 1 if csi1>5

The second line of code creates a new variable, csi1strong, that is equal to the sum of CSI1strong for all rows of data, by survey. 

 

 

How can I reproduce this in SAS?

 

Thank you in advance for your help!

Eva

1 REPLY 1
ballardw
Super User

@evat wrote:

Hi! I'm a long-time stata user and new to sas. I'm trying to figure out how to create a new variable based on the sum of the values of another variable.

 

In stata, I can do this using the "egen" command. For example,

 

gen CSI1strong = 1 if csi1>5 

egen csi1strong=sum(CSI1strong), by(survey) 

 

The first line of code creates a new variable, CSI1strong, that is equal to 1 if csi1>5

The second line of code creates a new variable, csi1strong, that is equal to the sum of CSI1strong for all rows of data, by survey. 

 

 

How can I reproduce this in SAS?

 

Thank you in advance for your help!

Eva


It would help SAS users more to provide an example of the starting data, the desired result and a description of what goes on if the two examples aren't very straight forward.

SUMing a variable in groups can be done in Proc Means or summary with the groups defined by CLASS variable(s), or in Proc Sql with a Group by.

Then combine the results, how will depend on the data sets.

I don't speak STATA, so that syntax means nothing.

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1 reply
  • 1531 views
  • 0 likes
  • 2 in conversation