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.
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!
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.