SAS Programming

DATA Step, Macro, Functions and more
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,

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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
  • 1714 views
  • 0 likes
  • 3 in conversation