BookmarkSubscribeRSS Feed
fabdu92
Obsidian | Level 7

Hi all,

 

At the end of a program I want to save a table from the WORK library to another library.The table name can also change.

 

Then I created the macro SAVING:

 

%macro SAVING(
	library, 
	input_table,
	output_table);

PROC COPY 
inlib=WORK outlib= &library.;
SELECT &input_table.;
run;

%if %sysfunc(exist(&library..&output_table.)) %then %do;
	PROC DELETE DATA= &library..&output_table.;
%end;

PROC DATASETS NOPRINT library=&library.;
    change &input_table.= &output_table.;
run;
quit;
%mend;

My table name is store in a macrovariable. named outname.

I want to call the macro with the macrovariable name.

data _null_;

call execute('%SAVING(
					library = OUT_LIB,
					input_table = FINAL_TABLE,
					output_table = &outname.)');
run;

But when I do this I have an issue in front of the "change" row of the macro

73: LINE and COLUMN cannot be determined.
ERROR 73-322: Expecting an =.

Do you know what is wrong?

Thanks,

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You need to put double quotes around the text to invoke macro variables:

data _null_;
 call execute(cats('%saving(library=out_lib,input_table=final_table,output_table=',"&outname.".');'));
run;

Although I fail to see the need for that code, simply:

data outlib.&outname.;
  set inlib.&outname.;
run;

Does exactly the same job, with none of that fuss.

fabdu92
Obsidian | Level 7

Thanks for the reply.

 

It is not exactly the same code, as in your case I have also a copy of FINAL_TABLE in the output library.

 

I could do this way nevertheless:

%macro SAVING(
	library, 
	input_table,
	output_table);

data &library..&output_table.;
set WORK.&input_table.;
run;

PROC DELETE DATA= &libray..&input_table.;
quit;
%mend;

But when I try this:

data _null_;
 call execute(cats('%saving(library=out_lib,input_table=final_table,output_table=',"&outname.".');'));
run;

I have this issue in front of the macrovariable outname:

ERROR 388-185: Expecting an arithmetic operator.

ERROR 200-322: The symbol is not recognized and will be ignored.

 Edit: This is how I create my macrovariable:

%let outname = p_201803;
Kurt_Bremser
Super User

First of all, you can greatly reduce the complexity of the call execute with the macro variable:

call execute('%saving(temp,class,' !! "&outname" !! ');');

But then, you need to take care of timing when calling a macro that contains macro code with call execute:

libname temp '/tmp';

data work.class;
set sashelp.class;
run;

%macro SAVING(
	library, 
	input_table,
	output_table);

PROC COPY 
inlib=WORK outlib= &library.;
SELECT &input_table.;
run;

%put executing macro statements;
%if %sysfunc(exist(&library..&output_table.)) %then %do;
	PROC DELETE DATA= &library..&output_table.;
%end;

PROC DATASETS NOPRINT library=&library.;
    change &input_table.= &output_table.;
run;
quit;
%mend;

%let outname=class1;

data _null_;
call execute('%saving(temp,class,' !! "&outname" !! ');');
run;

data _null_;
call execute('%nrstr(%saving(temp,class,' !! "&outname" !! '));');
run;

Closely examine the logs from the two data _null_ / call execute steps. In the first, you will find that the %put happens BEFORE the first data step runs, while in the second, it happens where you intend your macro statements to execute. That is the function of the %nrstr() wrapped around the macro call.

Why does this happen?

When call execute pushes code onto the stack, and macro code is detected, the macro code is immediately handed over to the macro processor, while all data or procedure steps have to wait until the data step that makes the call execute has ended. %nrstr prevents immediate resolution of the macro statements contained inside, and so the macro keeps its timing.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

There was a typo, dot rather than comma.

data _null_;
 call execute(cats('%saving(library=out_lib,input_table=final_table,output_table=',"&outname.",');'));
run;

 

Ksharp
Super User

Check system macro variable &syslast.

 

data class;
 set sashelp.class;
run;


data x;
 set &syslast ;
run;

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
  • 5 replies
  • 858 views
  • 1 like
  • 4 in conversation