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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.