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.
Var1 | Var2 | Var3 | VAR4 | Var5 | Last Updated |
A\U\AUD10MD156N.csv | 10-Month London Interbank Offered Rate (LIBOR), based on Australian Dollar | % | D | NSA | 2013-05-15 |
G\B\GBP10MD156N.csv | 10-Month London Interbank Offered Rate (LIBOR), based on British Pound | % | D | NSA | 2013-05-15 |
C\A\CAD10MD156N.csv | 10-Month London Interbank Offered Rate (LIBOR), based on Canadian Dollar | % | D | NSA | 2013-05-15 |
D\K\DKK10MD156N.csv | 10-Month London Interbank Offered Rate (LIBOR), based on Danish Krone (DISCONTINUED SERIES) | % | D | NSA | 2013-04-10 |
E\U\EUR10MD156N.csv | 10-Month London Interbank Offered Rate (LIBOR), based on Euro | % | D | NSA | 2013-05-15 |
J\P\JPY10MD156N.csv | 10-Month London Interbank Offered Rate (LIBOR), based on Japanese Yen | % | D | NSA | 2013-05-15 |
N\Z\NZD10MD156N.csv | 10-Month London Interbank Offered Rate (LIBOR), based on New Zealand Dollar (DISCONTINUED SERIES) | % | D | NSA | 2013-03-07 |
S\E\SEK10MD156N.csv | 10-Month London Interbank Offered Rate (LIBOR), based on Swedish Krona (DISCONTINUED SERIES) | % | D | NSA | 2013-04-10 |
C\H\CHF10MD156N.csv | 10-Month London Interbank Offered Rate (LIBOR), based on Swiss Frank | % | D | NSA | 2013-05-15 |
U\USD10MD156N.csv | 10-Month London Interbank Offered Rate (LIBOR), based on U.S. Dollar | % | D | NSA | 2013-05-15 |
D\T\DTP10J22.csv | 10-Year 0-1/8% Treasury Inflation-Indexed Note, Due 1/15/2022 | % | D | NSA | 2013-05-15 |
D\T\DTP10J23.csv | 10-Year 0-1/8% Treasury Inflation-Indexed Note, Due 1/15/2023 | % | D | NSA | 2013-05-15 |
D\T\DTP10L22.csv | 10-Year 0-1/8% Treasury Inflation-Indexed Note, Due 7/15/2022 | % | D | NSA | 2013-05-15 |
D\T\DTP10L21.csv | 10-Year 0-5/8% Treasury Inflation-Indexed Note, Due 7/15/2021 | % | D | NSA | 2013-05-15 |
D\T\DTP10L20.csv | 10-Year 1-1/4% Treasury Inflation-Indexed Note, Due 7/15/2020 | % | D | NSA | 2013-05-15 |
T\P\TP10L20.csv | 10-Year 1-1/4% Treasury Inflation-Indexed Note, Due 7/15/2020 | % | M | NSA | 2013-05-01 |
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
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, "/io" part of your code, I guess 'i' is to ignore case, is it? and what the 'o' do?
Thanks,
Haikuo
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
I see. I have been always wondering and always forgot asking. Thank you, PG!
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.
That works, I've not messed with prxmatch thanks,
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.