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


Hi, I keep getting an error message when I include references in the ods file statement. I would like to something similiar to the first ods tagsets file statement so that a report would be generated similiar to the second ods tagsets file name. Thanks in advance.

%LET begperiod = intnx('Year.4',intnx('Month',today(),-1,'E'),0,'B');
%LET endperiod = put(intnx('Month',today(),-1,'e'),monyy7.);

ods tagsets.excelXP file="U:\2013-14 Income Reports\Incomerpt&begperiod up to end of &endperiod.xls";

ods tagsets.excelXP file="U:\2013-14 Income Reports\Incomerpt2013 up to end of Dec2013.xls";

1 ACCEPTED SOLUTION

Accepted Solutions
RichardinOz
Quartz | Level 8

I would not expect SAS functions to be resolved in an ods statement.  Instead use %sysfunc in the macro variable definitions:

%LET begperiod = %sysfunc(intnx(Year.4, %sysfunc(intnx(Month, %sysfunc(today()),-1,E)),0,B));
%LET endperiod = %sysfunc(putN(%sysfunc(intnx(Month, %sysfunc(today()),-1,e)),monyy7.));

ods tagsets.excelXP file="U:\2013-14 Income Reports\Incomerpt&begperiod up to end of &endperiod.xls";

Alternately do the calculations in a data _Null_ step :

data _Null_ ;

     begperiod = intnx('Year.4',intnx('Month',today(),-1,'E'),0,'B');
     endperiod = put(intnx('Month',today(),-1,'e'),monyy7.);

     Call Symput ('begperiod'begperiod) ;   /*  leading spaces  */

     Call Symput ('endperiod'endperiod) ;

run ;

%Let begperiod = &begperiod ;      /*     to manage trimming     */

The code is going to deliver a SAS date numeral for &begperiod - is that what you want?

(Untested - check for missing or misplaced parentheses, use putn instead of put)

Richard temporarily back in Oz

View solution in original post

6 REPLIES 6
ballardw
Super User

Please post errors generated by code when asking questions related to errors.

RichardinOz
Quartz | Level 8

I would not expect SAS functions to be resolved in an ods statement.  Instead use %sysfunc in the macro variable definitions:

%LET begperiod = %sysfunc(intnx(Year.4, %sysfunc(intnx(Month, %sysfunc(today()),-1,E)),0,B));
%LET endperiod = %sysfunc(putN(%sysfunc(intnx(Month, %sysfunc(today()),-1,e)),monyy7.));

ods tagsets.excelXP file="U:\2013-14 Income Reports\Incomerpt&begperiod up to end of &endperiod.xls";

Alternately do the calculations in a data _Null_ step :

data _Null_ ;

     begperiod = intnx('Year.4',intnx('Month',today(),-1,'E'),0,'B');
     endperiod = put(intnx('Month',today(),-1,'e'),monyy7.);

     Call Symput ('begperiod'begperiod) ;   /*  leading spaces  */

     Call Symput ('endperiod'endperiod) ;

run ;

%Let begperiod = &begperiod ;      /*     to manage trimming     */

The code is going to deliver a SAS date numeral for &begperiod - is that what you want?

(Untested - check for missing or misplaced parentheses, use putn instead of put)

Richard temporarily back in Oz

twildone
Pyrite | Level 9

Hi Richard,

I tried both of your suggestions. When I tried to use the %sysfunc in the macro variable definitions, I would get an error message indicating that one of the arguments is not a number.

However when I tried your suggestion of doing the calculations in a data _Null_ step and Rezza suggestion of including periods after the end of the macro variables in the file= so the macro variables will resolve properly,  it worked fine. Thanks once again for your much appreciated help and suggestions.

RichardinOz
Quartz | Level 8

@twildone

Sorry about the lag in replying.  I do not know why you are getting the error you reported.  After adding the extra period in the one place, before the xls (Duh! thanks Reeza) and using a %Put before the ods statement for the purpose of demonstration this is what I got

15         %LET begperiod = %sysfunc(intnx(Year.4, %sysfunc(intnx(Month,

15       ! %sysfunc(today()),-1,E)),0,B));

16         %LET endperiod = %sysfunc(putN(%sysfunc(intnx(Month, %sysfunc(today()),-1,e)),monyy7.));

17        

18         %Put ods tagsets.excelXP file="U:\2013-14 Income Reports\Incomerpt&begperiod up to end of

18       ! &endperiod..xls";

ods tagsets.excelXP file="U:\2013-14 Income Reports\Incomerpt19449 up to end of DEC2013.xls"

[Log from EG 5.1 with server SAS 9.3 - not that I would expect any different from an earlier version]

However, the Data _Null_ approach is perhaps the best way to go - easier to follow, easier to debug, no %sysfuncing!

Richard in NZ

RichardinOz
Quartz | Level 8

Just checking on your original question there is also a missing Year() function to convert the SAS date in &begperiod to the year value.

Richard

Reeza
Super User

You'll also need periods after the end of the macro variables in the file= so the macro variables will resolve properly.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 6 replies
  • 736 views
  • 3 likes
  • 4 in conversation