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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—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
  • 2 replies
  • 1346 views
  • 0 likes
  • 3 in conversation