Hello
I would like to ask 2 questions please:
Question 1:
prxmatch('/ttt\d{8}/i',MEMNAME)
What does it mean ?
As I see it tells to take data sets names that have the word "ttt"?
What does it mean d{8}/i'???
Question 2:
input("&start",DDMMYY8.) <= input(compress(MEMNAME,,'a'),DDMMYY8.) <= input("&end",MMDDYY8.);
As I understand the date in data set name should be between start and end.
What does it mean input(compress(MEMNAME,,'a'),DDMMYY8.)??
I understand that input (......,DDMMYY8.) convert char to SAS date.
compress deleting spaces, what 'a' is doing?
Is it removing all upper and lower case characters from String (and only numbers left)?
thank you
and prxmatch('/ttt\d{8}/i',MEMNAME)
and input("&start",DDMMYY8.) <= input(compress(MEMNAME,,'a'),DDMMYY8.) <= input("&end",MMDDYY8.);
data ttt01032021;
input x y;
cards;
1 10
;
run;
data ttt02032021;
input x y;
cards;
2 11
;
run;
data ttt03032021;
input x y;
cards;
5 18
;
run;
data ttt06032021;
input x y;
cards;
6 16
;
run;
data ttt08032021;
input x y;
cards;
7 19
;
run;
%let start=01032021;
%let end=06032021;
proc sql noprint;
select MEMNAME into :ds separated by ' '
from dictionary.tables
where LIBNAME = 'WORK'
and prxmatch('/ttt\d{8}/i',MEMNAME)
and input("&start",DDMMYY8.) <= input(compress(MEMNAME,,'a'),DDMMYY8.) <= input("&end",MMDDYY8.);
quit;
%put &ds;
As always, make use of the documentation:
PRXMATCH Function (from there, go to Tables of Perl Regular Expression (PRX) Metacharacters)
-> you will see that \d{8} searches for 8 consecutive digits, and /i means "case insensitive"
COMPRESS Function (the modifier "a")
So probably prxmatch('/ttt\d{8}/i',MEMNAME) is equivalent to prxmatch('/ttt\d{8}/i',MEMNAME) =1 ??
Why is it like that??
How SAS guess that prxmatch('/ttt\d{8}/i',MEMNAME) is =1??
You really, really, really need to start studying the documentation. It's all in there:
Searches for a pattern match and returns the position at which the pattern is found.
To illustrate this, run a short example (Maxim 4):
data test;
input memname $32.;
pmatch = prxmatch('/ttt\d{8}/i',MEMNAME);
datalines;
xxx
ttt
ttt20210315
TTT20210315
ttt202103159
xxxttt20210315
;
You can see the returned positions.
Since SAS considers any numeric value not in (.,0) as true, the function can be used as the sole argument to a condition.
It's not that you don't understand prxmatch, it's just that you don't understand that the notation 'and prxmatch('/ttt\d{8}/i',MEMNAME)' is a condition.
prxmatch('/ttt\d{8}/i',MEMNAME) equal
prxmatch('/ttt\d{8}/i',MEMNAME) not in (. 0).
both of them is the same.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.