Happy Holidays!
Could you please explain why the value TYPE after the modification couldn’t give correct answer? The correct answer should be like this but the code didn't give this. Why? Thank you!
Type Frequency
. 1
3 1
5 4
data lk;
input id type;
datalines;
1 1
2 2
3 3
;
run;
data test;
input id;
datalines;
1
1
2
2
3
4
;
run;
data test1;
merge test(in=in1) lk;
by id;
if in1;
if type in (1,2) then type=5;
else if type ^= 3 then type=.;
run;
proc freq data=test1; tables type/list missing; run;
You are retaining the modified value. It will do as you expect if you use:
data test1 (drop=_type);
merge test(in=in1) lk (rename=(type=_type));
by id;
if in1;
if _type in (1,2) then type=5;
else if _type ^= 3 then type=.;
else type=3;
run;
You are retaining the modified value. It will do as you expect if you use:
data test1 (drop=_type);
merge test(in=in1) lk (rename=(type=_type));
by id;
if in1;
if _type in (1,2) then type=5;
else if _type ^= 3 then type=.;
else type=3;
run;
Thank you! It should be the reason.
You have used type instead of id in the if condition.
data test1;
merge test(in=in1) lk;
by id;
if in1;
if id in (1,2) then type=5;
else if id ^= 3 then type=.;
run;
proc freq data=test1; tables type/list missing; run;
Please used the above code to get the desired result.
Thanks,
Jag
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.