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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1109 views
  • 0 likes
  • 4 in conversation