Help using Base SAS procedures

Macro error

Accepted Solution Solved
Reply
Super Contributor
Posts: 1,041
Accepted Solution

Macro error

Hi,

When I run this code I get an error

Apparent symbolic reference DSET not resolved

Could you help me overcome this??

options symbolgen mlogic;


Accepted Solutions
Solution
‎04-13-2013 09:07 PM
Super User
Super User
Posts: 7,050

Re: Macro error

Posted in reply to robertrao

You cannot refer to the value of local macro variables (all macro parameters are local to the macro) outside of the macro.  So you cannot refer to them in the call to the macro.

You would be better off just copying the text twice or using another line of code in the calling program to create a macro variable.

%let name=vent7w2011May ;

%ventilator(dset=&name, itb_extb=intext.combined&name);



View solution in original post


All Replies
Solution
‎04-13-2013 09:07 PM
Super User
Super User
Posts: 7,050

Re: Macro error

Posted in reply to robertrao

You cannot refer to the value of local macro variables (all macro parameters are local to the macro) outside of the macro.  So you cannot refer to them in the call to the macro.

You would be better off just copying the text twice or using another line of code in the calling program to create a macro variable.

%let name=vent7w2011May ;

%ventilator(dset=&name, itb_extb=intext.combined&name);



Super Contributor
Posts: 1,041

Re: Macro error

Hi Tom,

Could you clarify this a little bit for me...

the dset changes for every call of the macro so I cannot put it in the %let as well??????

Regular Contributor
Posts: 227

Re: Macro error

Posted in reply to robertrao

Do you have a list of data sets to process?

http://www.sascommunity.org/wiki/Making_Lists

Super Contributor
Posts: 1,041

Re: Macro error

Posted in reply to Ron_Fehd_macro_maven

Hi Thanks for the reply I think I got it..

But could you tell me how can I use Set statement to acheive this same thing??

This is inside of a macro and each time you call a macro the results I get I want to append to the previous

Thanks

proc append base=intext.final_all data=intext.&itb_extb;

run;


Super User
Super User
Posts: 7,050

Re: Macro error

Posted in reply to robertrao

proc append base=intext.final_all data=intext.&itb_extb;

run;

Says to append the records from intext.&itb_extb to the end of intext.final_all.


You can do the same with a data step like:

data intext.&itb_extb  ;

  set intext.&itb_extb  intext.final_all ;

run;

Super Contributor
Posts: 1,041

Re: Macro error

i have a little confusion here

would it not be :

data intext.final_all ;

  set intext.final_all  intext.&itb_extb ;

run;

Super Contributor
Posts: 1,041

Re: Macro error

Posted in reply to robertrao

Does it matter at all?either way works??

Thanks

Super User
Super User
Posts: 7,050

Re: Macro error

Posted in reply to robertrao

Doesn't really matter. The only difference would be order of the records in the table.

The disadvantage of using this method is that as the FINAL_ALL table grows this step will get slower and slower as it has to keep copy over all of the previous records.  The discussion before about placing the names into a macro variable or list of macro variables and then looping over the macro variables to generate a single SET statement that listed all of the datasets would execute faster.  But it depends on the size of the tables whether the difference is significant for your application.

Super Contributor
Posts: 1,041

Re: Macro error

But Tom

in the example below

for the first call this is OK

In the second call  intext.&itb_extb changes and  intext.final_all  has nothing prior

So we will be having the contents of only the dataset in the second call???

Please correct me

In the end we will have only the records from the last dataset???

data intext.&itb_extb  ;

  set intext.&itb_extb  intext.final_all ;

run;

Super User
Super User
Posts: 7,050

Re: Macro error

Posted in reply to robertrao

You are right. I reversed the BASE and DATA table names.  The order in the SET statement doesn't matter very much, but which one is specified in the DATA statement is critical.

Super Contributor
Posts: 1,041

Re: Macro error

Thanks Tom for the clarification..

Regards

Super Contributor
Posts: 1,041

Re: Macro error

So, Instead of

data intext.final_all ;

  set intext.final_all  intext.&itb_extb;

   run;

YOU PUT

data intext.&itb_extb  ;

  set intext.&itb_extb  intext.final_all ;

run;

In both of these the first one is to be followed right???


Super Contributor
Posts: 1,041

Re: Macro error

Hi,

I tried to use it and either of the cases it says:

intext.final_all ; doesnot exist??????

Please let me know how to deal with this???

Thanks

Super User
Super User
Posts: 7,050

Re: Macro error

Posted in reply to robertrao

In any of these accumulation type programs you need to "prime the pump" in some way.  That is one of the advantages of using PROC APPEND as it is happy to handle the case when the BASE dataset does not already exist.

One way to deal with it is to add some logic to your macro.  Such as by making the inclusion of the final dataset conditional on it already existing as in the code fragment below.

data intext.final_all ;

  set

%if exist(intext.final_all) %then intext.final_all ;

   intext.&itb_extb ;

run;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 16 replies
  • 470 views
  • 7 likes
  • 3 in conversation