my data is like this
data test;
infile cards truncover;
input peat1 peat2;
datalines;
0 .
3 .
6 .
24 6
15 .
18 0
;
use the following code, I generated two new variables, peat1_ and peat2_.
data test_;
set test;
if 0=<peat1=<6 and peat1 ^=. then peat1_=1;
if 0=<peat2=<6 and peat2 ^=. then peat2_=1;
run;
Now I want to replace values of peat1 with values of peat2_, which SAS function should I use? thanks!
Hi @superbug
Something like this ??
data test_;
set test;
if 0=<peat1=<6 and peat1 ^=. then peat1_=1;
if 0=<peat2=<6 and peat2 ^=. then do;
peat2_= 1;
peat1 = 1;
end;
run;
thanks. using the code you suggested, the original value of peat1 changed in row 4 and row 6, which is not I wanted.
Also, there's is no difference on peat1_ and peat2_ variables using your code and using my original code.
Hi @superbug
Could you please provide the expected output as it's not clear to me.
According to the IF condition you provided, there is no difference in calculation. I believe there is a mistake somewhere.
best,
I restructured my data. I'll consider to reach my final results in another way.
Thanks much for your time!
if not missing(peat2_) then peat1=peat2_;
- Cheers -
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.