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

Hello,

 

I'm trying to identify whether components in one column match the components in another column.

 

For example,

Person IDvar1start dateVar2v2_start datev2_end date
1Dog+Pig01/18/2018dog04/12/201804/19/2018
1Dog+Pig01/18/2018pig07/25/201808/22/2018
1Dog+Pig01/18/2018lion10/04/201811/15/2018

 

 

From the table, I want to set some conditions to identify the dates and var2. The conditions are 

1) "var2" does NOT contain any words or components of "var1"  or that there is no match in any of the components in both variables. 

2)  The start date for "var2" is 30 days after the start date for "var1".

 

Then, the table I want is,

Person IDvar1v1_start dateWANTv2_start datev2_end date
1Dog+Pig01/18/2018lion10/04/201811/15/2018

 

The method I tried so far is to mark whether to keep or remove based on the conditions I set. 

 

PROC SQL;

CREATE TABLE want AS

SELECT personid, var1, v1_startdate, var2, v2_startdate,

(Case when 

(v2_startdate > v1_startdate+30) & (var2 <> va1)) THEN 1 ELSE 0 END) AS KEEEP

FROM have

GROUP BY personid;

QUIT; 

 

Please let me know if you need any clarification! 

1 ACCEPTED SOLUTION

Accepted Solutions
japelin
Rhodochrosite | Level 12

How about this?

data want;
  set have;
  if (v2_startdate > v1_startdate+30) and (find(var1,var2,'it')=0);
run;

View solution in original post

3 REPLIES 3
japelin
Rhodochrosite | Level 12

How about this?

data want;
  set have;
  if (v2_startdate > v1_startdate+30) and (find(var1,var2,'it')=0);
run;
jsyang56
Fluorite | Level 6

It worked! I really appreciate your help.

 

Just so that I have a good understanding of what happened, what does 'it' do when it's in the function of FIND()? I never thought about trying out this way nor seen other responses. 

japelin
Rhodochrosite | Level 12

"i or I" ignores character case during the search.

If this modifier is not specified, FIND cannot searches "dog" in "Dog".

 

find(var1,var2,'i')

is same like

 

find(upcase(var1),upcase(var2))

 

 

 

"t or T" trims trailing blanks from string and substring.

If var1 or var2 has a long variable length, such as $100, it must be trimmed to include trailing blanks in the search.

 

find(var1,var2,'t')

is same as 

 

 

find(trim(var1),trim(var2))

 

https://documentation.sas.com/doc/en/pgmcdc/8.11/proccas/n0kcfmf5agtudun1v1zkvnbd7970.htm

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 503 views
  • 0 likes
  • 2 in conversation