BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lila_lmp
Calcite | Level 5

Hello,

 

I want to ba able to use this in a loop like:

 

data name; set dataset1;
do n = 1 to 100 ; 
y = row n+1 value of a certain variable - row n value of that variable;
output ;
end;
run;

 

Please can you help me writing y?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Below one option how to do this.

data have;
  do i=1 to 200;
    myvar+i*i;
    output;
  end;
run;

data want;
  set have(obs=100);
  set have(firstobs=2 keep=myvar rename=(myvar=myvarPlusOne));
  y=myvarPlusOne-myvar;
run;

View solution in original post

3 REPLIES 3
Patrick
Opal | Level 21

Below one option how to do this.

data have;
  do i=1 to 200;
    myvar+i*i;
    output;
  end;
run;

data want;
  set have(obs=100);
  set have(firstobs=2 keep=myvar rename=(myvar=myvarPlusOne));
  y=myvarPlusOne-myvar;
run;
lila_lmp
Calcite | Level 5
Thank you Patrick !!!
Ksharp
Super User
data have;
 set sashelp.heart;
run;

%let col=4;
%let row=6;

data _null_;
set sashelp.vcolumn(where=(libname='WORK' and memname='HAVE' and varnum=&col.));
call execute(cat('data want;set have;if _n_= ',&row.,';keep ',name,';run;'));
run;

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1581 views
  • 1 like
  • 3 in conversation