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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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.

Capture.JPG

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

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;

 

--
Paige Miller
jklaverstijn
Rhodochrosite | Level 12

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.

whs278
Quartz | Level 8

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.

 

EG_Regular_Expression_Search.png

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
Patrick
Opal | Level 21

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.

Capture.JPG

whs278
Quartz | Level 8
Thank you for this answer.

I guess what was confusing me was that SAS considers each row as a separate string so ^9 would match the same row.
ed_sas_member
Meteorite | Level 14
proc contents data=sashelp.cars out=want (where=(upcase(name) like 'CYL%'));
run;

SAS Innovate 2025: Register Now

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!

SAS Enterprise Guide vs. SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 2493 views
  • 1 like
  • 5 in conversation