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

Hello I would like to get all the references from a text file in Var2 that match Wyoming or WY.  I did right a routine that grabs WY specific items in VAR1 that substr(var1, 5, 7) = "WY";

This will grab most but not all of the files are consistent. So I would like to match things from the text field with the words wyoming, wy and etc.  See example.  And no Wyoming does not have a consistent place or structure in the text files. Sometimes it is middle and sometimes at the end of Var2. 

Var1Var2Var3VAR4Var5Last Updated
A\U\AUD10MD156N.csv10-Month London Interbank Offered Rate (LIBOR), based on Australian Dollar%DNSA2013-05-15
G\B\GBP10MD156N.csv10-Month London Interbank Offered Rate (LIBOR), based on British Pound%DNSA2013-05-15
C\A\CAD10MD156N.csv10-Month London Interbank Offered Rate (LIBOR), based on Canadian Dollar%DNSA2013-05-15
D\K\DKK10MD156N.csv10-Month London Interbank Offered Rate (LIBOR), based on Danish Krone (DISCONTINUED SERIES)%DNSA2013-04-10
E\U\EUR10MD156N.csv10-Month London Interbank Offered Rate (LIBOR), based on Euro%DNSA2013-05-15
J\P\JPY10MD156N.csv10-Month London Interbank Offered Rate (LIBOR), based on Japanese Yen%DNSA2013-05-15
N\Z\NZD10MD156N.csv10-Month London Interbank Offered Rate (LIBOR), based on New Zealand Dollar (DISCONTINUED SERIES)%DNSA2013-03-07
S\E\SEK10MD156N.csv10-Month London Interbank Offered Rate (LIBOR), based on Swedish Krona (DISCONTINUED SERIES)%DNSA2013-04-10
C\H\CHF10MD156N.csv10-Month London Interbank Offered Rate (LIBOR), based on Swiss Frank%DNSA2013-05-15
U\USD10MD156N.csv10-Month London Interbank Offered Rate (LIBOR), based on U.S. Dollar%DNSA2013-05-15
D\T\DTP10J22.csv10-Year 0-1/8% Treasury Inflation-Indexed Note, Due 1/15/2022%DNSA2013-05-15
D\T\DTP10J23.csv10-Year 0-1/8% Treasury Inflation-Indexed Note, Due 1/15/2023%DNSA2013-05-15
D\T\DTP10L22.csv10-Year 0-1/8% Treasury Inflation-Indexed Note, Due 7/15/2022%DNSA2013-05-15
D\T\DTP10L21.csv10-Year 0-5/8% Treasury Inflation-Indexed Note, Due 7/15/2021%DNSA2013-05-15
D\T\DTP10L20.csv10-Year 1-1/4% Treasury Inflation-Indexed Note, Due 7/15/2020%DNSA2013-05-15
T\P\TP10L20.csv10-Year 1-1/4% Treasury Inflation-Indexed Note, Due 7/15/2020%MNSA2013-05-01
1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

It is simple to do with Perl regular expression matching :

data wy;

set test;

if prxmatch("/\b(wy|wyoming)\b/io", var2);

run;

With your example data, it matches nothing.

PG

PG

View solution in original post

6 REPLIES 6
PGStats
Opal | Level 21

It is simple to do with Perl regular expression matching :

data wy;

set test;

if prxmatch("/\b(wy|wyoming)\b/io", var2);

run;

With your example data, it matches nothing.

PG

PG
Haikuo
Onyx | Level 15

PG, "/io" part of your code, I guess 'i' is to ignore case, is it? and what the 'o' do?

Thanks,

Haikuo

PGStats
Opal | Level 21

Right. i requires to ignore the case, o requests that the pattern be compiled only once during the datastep execution (otherwise it is recompiled at every call). - PG

PG
Haikuo
Onyx | Level 15

I see. I have been always wondering and always forgot asking. Thank you, PG!

ballardw
Super User

It may be that the function INDEXW is your friend here.

You didn't say how you want to indicate the presence but

data want;

     set have;

     WYflag = (indexw(upcase(var2),'WYOMING') >0 or indexw(upcaase(var2),'WY')>0);

run;

should create a flag variable =1 when either of the strings occur as a word ( for example showy wouldn't be counted as a match for wy) and 0 when neither is present in VAR2.

You may want to add delimiters to the INDEXW function if you data is likely to have something besides a space separating the words of interest.

Thalo
Calcite | Level 5

That works, I've not messed with prxmatch thanks,

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
  • 909 views
  • 0 likes
  • 4 in conversation