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!
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,
I would think it is
proc sql;
select var1, var2, sum(varx) as vary
from have
group by var1, var2;
quit;
see if it gives the same result.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.