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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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