BookmarkSubscribeRSS Feed
TimurShangareev
Calcite | Level 5

Is there any method, where I can extract dataset name from expressions like:

<work.ds(...where=(...))>

<ds(... where=(...))>

or somehow check that this expression is valid in macro calls (wthout PROC or DATA statements)?

2 REPLIES 2
PaigeMiller
Diamond | Level 26

@TimurShangareev wrote:

Is there any method, where I can extract dataset name from expressions like:

<work.ds(...where=(...))>

<ds(... where=(...))>

or somehow check that this expression is valid in macro calls (wthout PROC or DATA statements)?


Let me make sure I am understanding. You have some text, like

 

SASHELP.CLASS(where=(sex='F'))

 

and you want to determine the data set name (which is SASHELP.CLASS). Is that what you want?

 

Where do you want to do this? (In a SAS data step? Somewhere else?)

What is the source of the input text string?

--
Paige Miller
Tom
Super User Tom
Super User

@TimurShangareev wrote:

Is there any method, where I can extract dataset name from expressions like:

<work.ds(...where=(...))>

<ds(... where=(...))>

or somehow check that this expression is valid in macro calls (wthout PROC or DATA statements)?


It would help if you explained in more detail what you actually mean. Perhaps some example use cases would help?

 

You mentioned macro calls.  So in macro code here are a couple of simple things.

%let dsn=sashelp.class(where=(age>11));
%let valid=FALSE;
%let dsid=%sysfunc(open(&dsn));
%if &dsid %then %do;
  %let valid=TRUE;
  %let dsid=%sysfunc(close(&dsid));
%end;
%let name_only=%scan(&dsn,1,());
%let options=%substr(&dsn%str( ),%length(&name_only)+1);
%let memname=%scan(&name_only,-1,.);
%let libref=%scan(WORK.&name_only,-2,.);
%put &=dsn &=valid ;
%put &=name_only &=options;
%put &=libref &=memname ;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 123 views
  • 2 likes
  • 3 in conversation