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

Hello;

 

I currently have the following variables in my dataset.

c3r1 c3r2 c3r3 c3r4 c3r5 c3r6 c3r52 c3r56 c3ar1 c3ar2 

 

I want to compute a new variable using the following rule:

1. If C3r1 or c3r2 or c3r3 ... c3r56 = 8 or 9 and c3ar1 = missing, then new variable = 99.

 

data temp;
        set temp;
        C3a_RB_r1= c3ar1;
        if (c3r: = 8 or c3r: = 9) AND (c3ar1) = . then C3a_RB_r1= 99;

        C3a_RB_r2= c3ar2;
        if (c3r: = 8 or c3r: = 9) AND (c3ar2) = . then C3a_RB_r2= 99;

run;

 

For the sake of demonstration, I have included few variables here. I'm trying to get a succinct code.

Please note that I want to rebase c3ar1 and c3ar2 in the example above. In my original dataset, I have c3ar1 to c3ar15, and so I would want to create 15 new variables c3a_RB_r1 to c3a_RB_r15. c3r: = 8 or 9 will be constant.

 

It would be great if I could get some help.

 

Tanks,

Neel

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Sounds like you are trying to use real numbers (8,9,99) to indicate missing values. The best solution is probably to first convert the special values into missing values (either regular missing or one of the 27 special missing codes).  Then you are just testing for the missing values, which functions like N(),NMISS() and CMISS() can help with.  Plus the missing values will be properly handled when you use those variables in other analysis steps.

 

You can probably do what you want with the WHICHN() function.

if (whichn(8,of c3r:) or whichn(9,of c3r:)) and missing(c3ar1) then C3a_RB_r1= 99;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Sounds like you are trying to use real numbers (8,9,99) to indicate missing values. The best solution is probably to first convert the special values into missing values (either regular missing or one of the 27 special missing codes).  Then you are just testing for the missing values, which functions like N(),NMISS() and CMISS() can help with.  Plus the missing values will be properly handled when you use those variables in other analysis steps.

 

You can probably do what you want with the WHICHN() function.

if (whichn(8,of c3r:) or whichn(9,of c3r:)) and missing(c3ar1) then C3a_RB_r1= 99;
neeld1
Fluorite | Level 6
Thank you so much! This helps a ton.

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
  • 2 replies
  • 376 views
  • 1 like
  • 2 in conversation