used code
-----------------------------------------------------------------------------------------------
data tp;
set p ;
i=index(var1,'r') ;
if i=1 then do idnum1=input(compress(var1, ' ', 'A'), 5.) ;
end;
if i=2 then do idnum2=input(compress(var1, ' ', 'A'), 5.) ;
end;
run;
-----------------------------------------------------------------------------------------------
I want to make new variable(idnum3) from this dataset.
How could I make 'idnum3' 1 to 20 using last observation of 'idnum1' add to 'idnum2'.
If you have any idea please tell me.
thank you.
data have;
input var1 $;
i=index(var1,'r');
if i=1 then idnum1=input(compress(var1, ' ', 'A'), 5.) ;
if i=2 then idnum2=input(compress(var1, ' ', 'A'), 5.) ;
datalines;
rt01
rt02
rt03
rt04
rt05
rt06
rt07
rt08
rt09
rt10
tr01
tr02
tr03
tr04
tr05
tr06
tr07
tr08
tr09
tr10
;
proc sql;
select max(idnum1) into :max from have;
quit;
data want;
set have;
idnum3=sum(&max,idnum2);
run;
Assuming that the portion of code that you posted is working as intended, you could add to the same DATA step:
retain last_idnum1;
if idnum1 > . then do;
idnum3 = idnum1;
last_idnum1 = idnum1;
end;
else idnum3 = sum(last_idnum1, idnum2);
Good luck.
And if you want a simple row counter, assuming you may have more data
add
idnum3 = _n_; to the same data step.
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!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.