Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro resolution query

Status
Not open for further replies.

Asender

Programmer
Jun 4, 2003
31
GB
Hi.

Apologies first for a long post.

I am calling a macro from a dataset which contains the locations of several SAS logs.

Once the log has been checked I create a macro variable which I want included in the subject field of an email which is created within the macro program.

My problem is that the macro variable I created is not available when the code is executed, but I don't understand why.

Here is a rough representation of my code:

Code:
%macro my_macro;

data _null_;
	set test;
	call symput('rc_level',var1);
run;

filename eout email 

To = "email_address"
Subject = "Job has completed with &rc_level."
Attach = ("log summary");

data _null_;
  file eout;
   put 'LOG Summary attached';
   put ' ';
run;

filename eout clear;

%mend my_macro;

*** This DS contains several observations;
data _null_;
  set log_list;
	call execute('%my_macro');
run;

Having spent some time looking into this I gather that the macro program is stored in a macro catalogue until a call to it is made. At which point the program is placed back into the Input Stack and tokenised as normal. I appreciate that this is a simplification and I may also be wrong.

This is where my 'understanding' fails.

I think that the first data step should have been compiled and executed before the second, and as such the macro variable 'rc_level' should be available for the 'filename' statement to resolve. But the log suggests that this is not the case as I get the appropriate 'WARNING: Apparent symbolic reference RC_LEVEL not resolved' message.

I have managed to get this process to work (after a fashion), but more by hacking than design. Here is the code for that (changes in red):

Code:
%macro my_macro;

[COLOR=red]%symdel rc_level;[/color red]

data _null_;
	set test;
	call symput('rc_level',var1);
run;

filename eout email 

To = "email_address"
Subject = "Job has completed with [COLOR=red]&&[/color red]&rc_level."
Attach = ("log summary");

data _null_;
  file eout;
   put 'LOG Summary attached';
   put ' ';
run;

filename eout clear;

%mend my_macro;

*** This DS contains several observations;
data _null_;
  set log_list;
	call execute('%my_macro');
run;

This does get me the results I want but again with the 'WARNING: Apparent symbolic reference RC_LEVEL not resolved' in the log.

Can anyone help me understand this?

Thanks for your patience and time.

Kind regards,


Asender

 
Hi Asender,

I tried the following and it seems to work. Although I dont know what kind of data is in your test dataset:

Code:
options symbolgen mlogic mprint;


data log_list;
  input @1 var $9.;
  cards;
test1
test2
test3
test4
;
run;


%macro my_macro;

data _null_;
    set log_list;
    call symput('rc_level',var);
run;

filename eout email 

To = "email_address"
Subject = "Job has completed with &&rc_level."
Attach = ("log summary");

data _null_;
  file eout;
   put 'LOG Summary attached';
   put ' ';
run;

filename eout clear;

%mend my_macro;

*** This DS contains several observations;
data _null_;
  set log_list;
    call execute('%my_macro');
run;

If you haven't already done so, the options mlogic mprint and symbolgen are good for debugging macro problems.

Macro statements are passed to the macro processor and executed before the datasteps, so I beleive you are right in that the creation of the rc_level macro variable should be the first thing processed.

I think you should only need the two ampersands when using indirect referencing in this case, as the two ampersands resolve to one on the first scan.

Let me know if this works.

cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top