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-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

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
  • 1890 views
  • 1 like
  • 3 in conversation