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
@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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.