DATA Step, Macro, Functions and more

Macro error

Reply
PROC Star
Posts: 633

Macro error

[ Edited ]

In the following code, the macro &table_list resolves to test_1,test_5,test_9 and these tables are available in the library DEXVCOM as well. But when I run code, I'm receiving an error 

 

"ERROR: File WORK.test_1 does not exist"

"ERROR: File WORK.test_5 does not exist".

"ERROR: File WORK.test_9  does not exist"

 

Macro has resolved correctly.

 

data want;
set DEXVCOM.&table_list.;
run;

Appreciate if someone of you guide me to resolve the issue. I don't want to hard code the 'table list' value and I wish to get it dynamically.

Contributor
Posts: 49

Re: Macro error

I guess you are trying to append all the datasets , but while appending the dataset in a set statement you don't need to give a comma between 2 datasets name 

 

so change your macro value (it should resolve to test_1 (space) Test_2) and then run the code , it will work

PROC Star
Posts: 633

Re: Macro error

Posted in reply to soham_sas

To be more clear, I received an error as follows.

 

"ERROR: File WORK.test_1 does not exist"

"ERROR: File WORK.test_5 does not exist".

"ERROR: File WORK.test_9  does not exist"

 

Macro has resolved correctly.

 

Super User
Super User
Posts: 9,813

Re: Macro error

[ Edited ]

I am sure we have been over this time and time again.  Macro language is a textual find and replace tool, which is an additional component of Base SAS.  Base SAS is the lanauge which you should learn be 100% familiar with before you attempt any macro, which is never ever needed.  Why do I keep saying this, it is because the question shows a distinct lack of understanding of Base SAS, lets take your given example of table_list being = test_1,test_5,test_9.  We take that text and replace the macro variable with that text - this is all the macro processor is doing again:

data want;
  set dexvcom.test_1,test_5,test_9;
run;

Once we use indents and correct the upcase coding, then we see the code above.  Does this look like the Base SAS coding which can be compiled and executed and do what you require.  The answer is no.  Now the next question to ask yourself is why you have things in the macro variable in the first place, from above we can see that macro does nothing, it is not executable or usable, it is purely a text find and replace system, Base SAS is the programming language, and so what we will do is use the programming language to perform the task:

 

PROC Star
Posts: 633

Re: Macro error

Thank you for the insights. Is there a way to loop the dataset name via macro? Appreciate if you could help me to tackle this scenario.

Super Contributor
Posts: 354

Re: Macro error

Hello,

 

set %sysfunc(prxchange(s/([a-z0-9_]+)%str(,)*/dexvcom.${1}%str( )/,-1,%quote(&table_list.)));
Super User
Posts: 6,921

Re: Macro error

If you're going to program using macro language, it's a topic you will need to learn.  Here's some help:

 

https://blogs.sas.com/content/sastraining/2015/01/30/sas-authors-tip-getting-the-macro-language-to-p...

 

Super User
Posts: 13,909

Re: Macro error

The SAS options Mprint Symbolgen and Mlogic (if your macro has %if type statements to resolve logic) will show the code generated by your use of macro code.

 

options mprint symbolgen;

data want;
set DEXVCOM.&table_list.;
run;

 

And look at the log to see what code was actually generated.

options nomprint nosymbolgen;

to reset the options.

 

 

 

 

Super User
Posts: 23,980

Re: Macro error

You need to post your full code and log, not snippets. 

The concept of a minimum reproducible example is what will get you help faster and half the time you'll solve  your own problem if you follow these steps.

 

https://stackoverflow.com/help/mcve

 


Babloo wrote:

In the following code, the macro &table_list resolves to test_1,test_5,test_9 and these tables are available in the library DEXVCOM as well. But when I run code, I'm receiving an error 

 

"ERROR: File WORK.test_1 does not exist"

"ERROR: File WORK.test_5 does not exist".

"ERROR: File WORK.test_9  does not exist"

 

Macro has resolved correctly.

 

data want;
set DEXVCOM.&table_list.;
run;

Appreciate if someone of you guide me to resolve the issue. I don't want to hard code the 'table list' value and I wish to get it dynamically.


 

Ask a Question
Discussion stats
  • 8 replies
  • 149 views
  • 0 likes
  • 7 in conversation