When using regular expressions, is there a way to use regular expressions to find a variable that starts with a certain string pattern in the listing after running PROC CONTENTS?
I have tried both \<MTH and ^MTH to find the variable MTHGRDG07 in my dataset but neither works.
Thank you very much.
Sincerely,
Bill
Try RegEx \bCYL
\b is for a word boundary, ^ is for beginning of the string.
Your string starts with blanks so the RegEx you've shown us can't match.
If you write the PROC CONTENTS output to a SAS data set (or use the equivalent dictionary table), searching is easily done via a WHERE statement, no regular expression needed (in this case).
proc contents noprint out=_contents_ data=mydataset;
run;
proc print data=_contents_(where=(upcase(name)='MTHGRDG07'));
run;
YTou can achieve that without proc contents. Query the dictionary tables or their views in SASHELP like this:
proc print data=sashelp.vcolumn(where=(libname='YOURLIB' and memname='YOURTABLE' and prxmatch('/^MTH/', name)));
run;
Wonder where the Ctrl-F comes into play. That would be a text editor specific question independent from the proc you run.
Hope this helps,
- Jan.
I think I wasn't clear in my first post. I am having trouble with the regular expression search tool when looking for variables in the output. Maybe the picture below will help.
@whs278 wrote:
I think I wasn't clear in my first post. I am having trouble with the regular expression search tool when looking for variables in the output. Maybe the picture below will help.
No, your explanation is clear. We are telling you there are simpler ways to do this than searching through a listing with regular expressions or by using Ctrl-F.
Try RegEx \bCYL
\b is for a word boundary, ^ is for beginning of the string.
Your string starts with blanks so the RegEx you've shown us can't match.
proc contents data=sashelp.cars out=want (where=(upcase(name) like 'CYL%'));
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.