BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Siennayun
Calcite | Level 5
If I have a column named “K” with 25 rows .
How can I add a new column DK[i]=K[i+1]+k[i-1] to the table?(when 2<i <25.)
I have no idea how to get the value of a particular row of a column.

Please give me some help
1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Below one way to go.

data have; 
  do k=1 to 25;
    output;
  end;
  stop;
run;

data want(drop=_k);
  merge have have(firstobs=2 keep=k rename=(k=_k));
  dk1=lag(k)+_k;
  dk2=sum(lag(k),_k);
run;

proc print data=want;
run;

Patrick_0-1591473526097.png

 

 

View solution in original post

4 REPLIES 4
ballardw
Super User

It usually helps to indicate some data and what you expect the output for that given data to be.

 

Does your data set have 25 observations or are you asking to only process some observations out of a larger set?

Patrick
Opal | Level 21

Below one way to go.

data have; 
  do k=1 to 25;
    output;
  end;
  stop;
run;

data want(drop=_k);
  merge have have(firstobs=2 keep=k rename=(k=_k));
  dk1=lag(k)+_k;
  dk2=sum(lag(k),_k);
run;

proc print data=want;
run;

Patrick_0-1591473526097.png

 

 

Siennayun
Calcite | Level 5
Thank you so much for your help.
I’ve figured it out.

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
  • 4 replies
  • 1781 views
  • 0 likes
  • 4 in conversation