good day,
below is my program structure;
test1 test2 Expected net
row1 100 90 10
row2 99 90 9
row3 98 90 8
row4 97 90 7
net=test1-test2;
if row(n) net=10 then row(n+1) test1 = 100 ;
if row(n) net=10 then row(n+1) test2 = 90 ;
the problem is when the SAS condition change row2 test1=100 and test2=90
you have to rerun the data step and get the correct net for row2
and after that row3 can meet the condition and make its changing
expected result:
test1 test2 net
row1 100 90 10
row2 100 90 10
row3 100 90 10
row4 100 90 10
the only solution i can figure out for now is manually run this script for 3 times then i can get my expected result.
so i am going to seek help in this forum.
anyone get a better way to do it?
Thanks in advance,
Harry
Hi @harrylui
Does the following code could meet your expectations?
data have;
input test1 test2;
datalines;
100 90
99 90
98 90
97 90
;
run;
data want;
set have;
if _n_=1 then net=test1-test2;
retain net;
test1 = 100;
test2 = 90;
run;
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 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.