Hello guys,
I' m new to the forum.
Please how do i create a new variable from 3 variables (cbrchyr, copdev, ephev).
My goal is to create a variable that would pick, for example, a "YES" response (coded as 1) in ANY of the variables cbrchyr, copdev and ephev to mean a "Yes" response in my new variable. While the remaining responses that are not "YES" (coded as 2,7,8,9) are coded as 2 (NO).
I have attached a copy of my output. I want to create a variable that would list obs 27, 37, 38, 44 and 47 as Yes (1).
Please i'll be glad to get any kind of help.
Below is my inital code. I have used the "coalsce" statement and i just can't get it right.
LIBNAME perm 'D:\';
DATA Newsasdata (keep= cbrchyr copdev ephev );
SET perm.nhis2012sampleadult;
RUN;
To paraphrase @ChrisNZ
var4=ifn(index(catt(var1,var2,var3),'1'),1,2);
So if the first parameter is true, return 1, else return 2
Like this?
if index(catt(VAR1,VAR2,VAR3),'1') then VAR4='Y';
Thank you!
It worked. My other question is, how do i code the other observations as "2" in my new variable (var 4)
To paraphrase @ChrisNZ
var4=ifn(index(catt(var1,var2,var3),'1'),1,2);
So if the first parameter is true, return 1, else return 2
Thanks Chris!
Thanks guys!
if index(catt(VAR1,VAR2,VAR3),'1') then VAR4='Y';
else var4='N'
?
//Fredrik
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 how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.