BookmarkSubscribeRSS Feed
harrylui
Obsidian | Level 7

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

 

 

1 REPLY 1
ed_sas_member
Meteorite | Level 14

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;
How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 665 views
  • 0 likes
  • 2 in conversation