BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
abdulla
Pyrite | Level 9
codedateRtrexpnew
2020110.1152250.114746 
2020120.1014240.116390.231615
2020130.1147460.0552480.156672
2320110.116390.094931 
2320120.0552480.1735080.289898
2320130.0949310.1905660.245813
5520110.0291430.073573 
5520120.0609950.0859150.115057
5520130.0699180.0754330.136429

 

I want to add rtr in 2011 with exp in 2012. So my result will be equal to as shown in New column. It is adding the lag value of rtr with the current value of exp. The result should be grouped by code. Please help. 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

You can do like this

 

data have;
input code date Rtr exp;
datalines;
20 2011 0.115225 0.114746
20 2012 0.101424 0.11639
20 2013 0.114746 0.055248
23 2011 0.11639 0.094931
23 2012 0.055248 0.173508
23 2013 0.094931 0.190566
55 2011 0.029143 0.073573
55 2012 0.060995 0.085915
55 2013 0.069918 0.075433
;

data want;
   set have;
   by code;
   lag_Rtr=lag1(Rtr);
   new=sum(lag_Rtr, exp);
   if first.code then new=.;
run;

View solution in original post

1 REPLY 1
PeterClemmensen
Tourmaline | Level 20

You can do like this

 

data have;
input code date Rtr exp;
datalines;
20 2011 0.115225 0.114746
20 2012 0.101424 0.11639
20 2013 0.114746 0.055248
23 2011 0.11639 0.094931
23 2012 0.055248 0.173508
23 2013 0.094931 0.190566
55 2011 0.029143 0.073573
55 2012 0.060995 0.085915
55 2013 0.069918 0.075433
;

data want;
   set have;
   by code;
   lag_Rtr=lag1(Rtr);
   new=sum(lag_Rtr, exp);
   if first.code then new=.;
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 1 reply
  • 440 views
  • 1 like
  • 2 in conversation