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

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;


Capture.JPG

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

View solution in original post

7 REPLIES 7
ChrisNZ
Tourmaline | Level 20

Like this?

if index(catt(VAR1,VAR2,VAR3),'1') then VAR4='Y';

 

ChuksManuel
Pyrite | Level 9

Thank you!

It worked. My other question is, how do i code the other observations as "2" in my new variable (var 4)Capture2.JPG

 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

FredrikE
Rhodochrosite | Level 12
if index(catt(VAR1,VAR2,VAR3),'1') then VAR4='Y';
else var4='N'

?

//Fredrik

SAS Innovate 2025: Register Now

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 7 replies
  • 1528 views
  • 1 like
  • 4 in conversation