BookmarkSubscribeRSS Feed
n7
Calcite | Level 5 n7
Calcite | Level 5

Hello,

 

I am working on converting some Stata code to SAS and running into trouble with a line including egen = sum(another variable):

 

bys var1 var2: egen vary= sum(varx)

 

Do you know how this could be translated into SAS code?

 

Thanks!

2 REPLIES 2
ed_sas_member
Meteorite | Level 14

Hi @n7 

Assuming that 'varx' as no missing value and that 'vary' corresponds to the sum of 'varx' value in each subgroup made of a unique combination of 'var1' and 'var2', you can try this: 

proc sql;
	create table want as
	select *, sum(varx) as vary
	from have
	group by var1, var2;
quit;

Best,

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1935 views
  • 0 likes
  • 3 in conversation