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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

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
  • 7 replies
  • 1217 views
  • 1 like
  • 4 in conversation