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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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