Write and run SAS programs in your web browser

Using a macro variable to name a datastep

Posts: 31

Using a macro variable to name a datastep

i am having problems using mcros.Not getting the desired output


data cudata;
input ID Orderdate$ Model$12. Quantity ;
287 15OCT03 DeltaBreeze 15
287 15OCT03 SantaAna 15
274 16OCT03 JetStream 1
174 17OCT03 SantaAna 20
174 17OCT03 Noreaster 5
174 17OCT03 Scirocco 1
347 18OCT03 Mistral 1
287 21OCT03 DeltaBreeze 30
287 21OCT03 SantaAna 25

%macro cus(dsn);

%if &sysday=Monday
%then %do;
proc print data=&dsn;

%else %if &sysday=Thursday
%then %do;
proc tabulate data=&dsn;
class ID;
var Quantity ;
table ID,Quantity;



%mend cus;





NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release. Inserting white space
between a quoted string and the succeeding identifier is recommended.
Super User
Super User
Posts: 7,720

Re: Using a macro variable to name a datastep

The problem is most likely not with that code directly.  If you run code which has an open quote, i.e. a quote mark with no closing mark, then SAS treates everything after that as being text.  That is what the warning is telling you that it has read a certain amount of "text" and thinks you have unbalanced quote marks.  Simplest solution, restart the SAS system to get a fresh session, and check any code you write to ensure all quoted strings is finished.

Also note, why bother with the whole macro thing?  Just run a proc print an tabulate, takes a fraction of a second, then send out one or the other file.

Posts: 28

Re: Using a macro variable to name a datastep

This isnt a full solution for you.

But the macro part of your problem works fine. 

That message is a warning that in future versions of SAS there will be a modification on how to use that style of code you tried for macros.

What version are you on?  I'm on 9.4.  so if you are on an earlier version that would explain things.  and it hampers my ability to recreate the exact message.


I'd like to suggest a few things...

1. your data step isnt reading in your data correctly.  Use:   infile datalines truncover;   

2. on things like the -tuesday- , -thursday-.  Try with them in quotes.

3. the use of %macro cus(dsn);   isnt bad - but might i suggest naming the macro variable?  Its easier to read... Example:   %macro cus(dsn=);     then when you call it you can use:    %cus(dsn=cudata);  Its expecially helpful with a macro that has many variables.




zeke torres


Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation