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

Hi,

 

Wonder if you can help. I'm trying to create a new variable which brings in variable names where they equal 1.

For example Reason is the variable I want to create.

 

Application_numberABCReason
5002110A,B
5003111A,B,C
5004001C
5005111A,B,C

 

I've tried a VNAME but could only get it to bring in 1 hit. My data source has 49 variables that could have a possible 1.

 

Thanks

Dan

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Try this

 

data have;
input Application_number A B C;
datalines;
5002 1 1 0 
5003 1 1 1 
5004 0 0 1 
5005 1 1 1 
;

data want;
   set have;
   array rr A B C;
   length Reason $ 100;
   do over rr;
      if rr then Reason = catx(',', Reason, vname(rr));
   end;
run;

 

Result:

 

Application_number  A  B  C  Reason 
5002                1  1  0  A,B 
5003                1  1  1  A,B,C 
5004                0  0  1  C 
5005                1  1  1  A,B,C 

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Try this

 

data have;
input Application_number A B C;
datalines;
5002 1 1 0 
5003 1 1 1 
5004 0 0 1 
5005 1 1 1 
;

data want;
   set have;
   array rr A B C;
   length Reason $ 100;
   do over rr;
      if rr then Reason = catx(',', Reason, vname(rr));
   end;
run;

 

Result:

 

Application_number  A  B  C  Reason 
5002                1  1  0  A,B 
5003                1  1  1  A,B,C 
5004                0  0  1  C 
5005                1  1  1  A,B,C 
danhopkinslewis
Fluorite | Level 6

Works a treat  @PeterClemmensen massive appreciation sent your way.

PeterClemmensen
Tourmaline | Level 20

Massive appreciation appreciated 🙂

PaigeMiller
Diamond | Level 26

@danhopkinslewis wrote:

Hi,

 

Wonder if you can help. I'm trying to create a new variable which brings in variable names where they equal 1.

For example Reason is the variable I want to create.

 

Application_number A B C Reason
5002 1 1 0 A,B
5003 1 1 1 A,B,C
5004 0 0 1 C
5005 1 1 1 A,B,C

 

I've tried a VNAME but could only get it to bring in 1 hit. My data source has 49 variables that could have a possible 1.


I curious, what could you possibly do with a string such as one you are trying to create, if it has 49 different possible variables? What benefits would there be, compared to working with the 0/1 variables?

--
Paige Miller

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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