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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.