BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
_maldini_
Barite | Level 11

I'm a complete novice w/ macros and this syntax produces an error I don't know how to rectify. Thanks for your help.

%LET macro = /home/maldini/EPG1V2/data/StormStats.xlsx;

ODS EXCEL FILE=&macro
	STYLE=snow
	OPTIONS (SHEET_NAME="South Pacific Summary");
TITLE "Some Relevant Title";
ODS NOPROCTITLE;

proc means data=pg1.storm_detail maxdec=0 median max;
    class Season;
    var Wind;
    where Basin='SP' and Season in (2014,2015,2016);
run;

ODS EXCEL CLOSE;

Here is the log: 

1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

 NOTE: ODS statements in the SAS Studio environment may disable some output features.

 73        

 74         %LET macro = /home/maldini/EPG1V2/data/StormStats.xlsx;

 75        

 76         ODS EXCEL FILE=&macro

 77         STYLE=snow

 NOTE: Line generated by the macro variable "MACRO".

 77         /home/jcorroon/EPG1V2/data/StormStats.xlsx

            _

            22

            200

 ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string. 

 

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

 

 78        

 79         OPTIONS (SHEET_NAME="South Pacific Summary");

 80        

 81         TITLE "Some Relevant Title";

 82         ODS NOPROCTITLE;

 83        

 84         proc means data=pg1.storm_detail maxdec=0 median max;

 85             class Season;

 86             var Wind;

 87             where Basin='SP' and Season in (2014,2015,2016);

 88         run;

 

 NOTE: There were 1132 observations read from the data set PG1.STORM_DETAIL.

       WHERE (Basin='SP') and Season in (2014, 2015, 2016);

 NOTE: PROCEDURE MEANS used (Total process time):

       real time           0.05 seconds

       user cpu time       0.04 seconds

       system cpu time     0.01 seconds

       memory              12025.96k

       OS Memory           44052.00k

       Timestamp           04/28/2022 06:04:03 PM

       Step Count                        58  Switch Count  3

       Page Faults                       0

       Page Reclaims                     2761

       Page Swaps                        0

       Voluntary Context Switches        30

       Involuntary Context Switches      0

       Block Input Operations            0

       Block Output Operations           8

      

 

 89        

 90         ODS EXCEL CLOSE;

 91        

 92        

 93         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

 105       

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Looks like you are asking about a macro variable (aka symbol) and not an actual macro.

 

The macro processor is just doing text replacement. So to tell if expanding a macro variable in your code will produce value syntax just replace the reference with the value.

So for:

FILE=&macro

You will get :

FILE=/home/maldini/EPG1V2/data/StormStats.xlsx

Which not valid SAS syntax.  The value of the FILE= option needs to be either a FILEREF or a quoted physical filename.

Try:

FILE="&macro"

instead.

Or add the quotes into the value of the macro variable.

%LET macro = "/home/maldini/EPG1V2/data/StormStats.xlsx" ;

ODS EXCEL FILE=&macro
...

View solution in original post

1 REPLY 1
Tom
Super User Tom
Super User

Looks like you are asking about a macro variable (aka symbol) and not an actual macro.

 

The macro processor is just doing text replacement. So to tell if expanding a macro variable in your code will produce value syntax just replace the reference with the value.

So for:

FILE=&macro

You will get :

FILE=/home/maldini/EPG1V2/data/StormStats.xlsx

Which not valid SAS syntax.  The value of the FILE= option needs to be either a FILEREF or a quoted physical filename.

Try:

FILE="&macro"

instead.

Or add the quotes into the value of the macro variable.

%LET macro = "/home/maldini/EPG1V2/data/StormStats.xlsx" ;

ODS EXCEL FILE=&macro
...

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 2790 views
  • 1 like
  • 2 in conversation