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
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;
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;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.