BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ying
Fluorite | Level 6

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;

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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;

View solution in original post

3 REPLIES 3
art297
Opal | Level 21

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;

Ying
Fluorite | Level 6

Thank you!  It should be the reason. 

Jagadishkatam
Amethyst | Level 16

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

Thanks,
Jag

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1281 views
  • 0 likes
  • 3 in conversation