Hello Everyone,
I stuck on one of the point.please help me out
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
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;
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.