BookmarkSubscribeRSS Feed
Dd07
Fluorite | Level 6

Hello Everyone,

I stuck  on one of the point.please help me out Smiley Frustrated

Scenario is We have two different variable in a dataset(Have) just like below

A      B     C

AA    w   a,b,c,d

BB   1     1,0,Null

CC  aa    AA,BBB,CCCC

DD   ab   a,b,c,d

 

I need a dataset (Want) as if the B varibale is part of c variable then create a flag as D and mark that as 1 else o 

 

A      B     C                           D

AA    w   a,b,c,d                    0

BB   1     1,0,Null                   1

CC  aa    AA,BBB,CCCC        1

DD   ab   a,b,c,d                    0

 

 

 

 

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

Well, no code as not typing in that test data.  You can check if the text appears in the string something like:

if index(c,b)>0 then d=1;

else d=0;

 

However your row CC, it is not logical the text "aa" is not found in the other string.  Do you have another rule you didn't mention which allow upper case to equal lower case, if so:

if index(upcase(c),upcase(b))>0 then d=1;

else d=0;

 

Astounding
PROC Star

Here are a couple of choices.

 

if findw(trim(C), trim(B), ',') > 0 then d=1;

else d=0;

 

if findw(trim(C), trim(B), ',', 'i') > 0 then d=1;

else d=0;

 

The "i" option will ignore upper vs. lower case, and would return 1 for the third observation.

 

Note that there are pitfalls that have to be addressed.  Since B takes on different lengths, I would assume you want to ignore trailing blanks that are part of B.  And INDEX searches for strings, not words.  So this comparison is true:

 

if index('abc,def', 'b') > 0 then D=1;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 2 replies
  • 1242 views
  • 0 likes
  • 3 in conversation