BookmarkSubscribeRSS Feed
Babloo
Rhodochrosite | Level 12

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.

8 REPLIES 8
soham_sas
Quartz | Level 8

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

Babloo
Rhodochrosite | Level 12

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.

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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:

 

Babloo
Rhodochrosite | Level 12

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.

gamotte
Rhodochrosite | Level 12

Hello,

 

set %sysfunc(prxchange(s/([a-z0-9_]+)%str(,)*/dexvcom.${1}%str( )/,-1,%quote(&table_list.)));
Astounding
PROC Star

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

 

ballardw
Super User

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.

 

 

 

 

Reeza
Super User

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.


 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 904 views
  • 0 likes
  • 7 in conversation