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

Hi,

I have a sas dataset with 2 variables. I would like to accomplish below. If the value of VAR2 is part of the string in VAR1 FIND needs to be 1, if not 0. How can I do this ? I've been trying out FINDC, CAT, INDEXC but none of these work.

 

Many thanks !

 

 

VAR1VAR2FIND
\TEST1\IPN R1\2012\2013\CLEARPATH-COMMANDS.TXTIPN R1\2012\DOCUMENT0
\TEST2\IPN R1\2009\DOCUMENTEN\TRIGGERS DATA_ACCES.TXTIPN R1\2009\DOCUMENT1
\TEST3\IPN R1\2006\DOCUMENTATION\VIEW SCH_RGL_GPH.SQLIPN R1\2006\DOCUMENT1
1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

One slight correction to @JohnHoughton's suggestion. Since you want 0s and 1s, use:

find=find(var1,var2,'t') gt 0;

Art, CEO, AnalystFinder.com

 

View solution in original post

6 REPLIES 6
JohnHoughton
Quartz | Level 8

Hi
use find (string , subtring)

 

If the substring has trailing blanks (which is most likely) then there are two options


1. Use the t modifier i.e find(string,substring,'t');

2. Use trimn on the substring ie find(string,trimn(substring));

(Use trimn rather than trim in case the substring variable is missing, because trim would return a blank)

art297
Opal | Level 21

One slight correction to @JohnHoughton's suggestion. Since you want 0s and 1s, use:

find=find(var1,var2,'t') gt 0;

Art, CEO, AnalystFinder.com

 

Billybob73
Quartz | Level 8

John and Art,

Thank you very much ! The final solution is :

 

find=find(%str(mapbestandsnaam),%str(trimn(stringyeardoc)),'t') gt 0;

 

I'm surprised this function won't try to resolve & s which are in the paths that I scan. Why is that ?

As you can see I'm using %str.

There can also be quotes and percentage signs in the paths so I would need to use %nrbquote also I guess.

 

Rgds

B

satkinson1351
Calcite | Level 5

How can I get the find function to work using a field that contains a comma separated list of numbers (i.e 610,610,613,614,675,675)?

ss171
Calcite | Level 5

if we want exact word match not the character match . how can we do using find ?

ex : var1 

awesome customer service today nashville Macys nashvillehospitality raineydayhelp Thanks

var 2 

awesome

Thanks 

day

help

output: it should consider awesome and Thanks only 

please suggest

art297
Opal | Level 21

You really ought to start a new thread when asking a new question. However, I think you are looking for the findw function. e.g.:

data have;
  informat var1 $200.;
  informat var2 $20.;
  input var1 & var2;
  find=findw(var1,var2,' .,','t');
  cards;
awesome customer service today nashville Macys nashvillehospitality raineydayhelp Thanks  awesome
awesome customer service today nashville Macys nashvillehospitality raineydayhelp Thanks  Thanks
awesome customer service today nashville Macys nashvillehospitality raineydayhelp Thanks  day
awesome customer service today nashville Macys nashvillehospitality raineydayhelp Thanks  help
;
run;

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
  • 6 replies
  • 10623 views
  • 1 like
  • 5 in conversation