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

Hi,

 

I am trying to append a macro to the end of an excel file that I am exporting, so the new file name will be filename_macro.xlsx. 

 

The macro variable is a date and right now it is outputting as the SAS date(just a number) with a space in front of the number. For example it looks like filename_ 21074.xlsx.

 

My final goal is to be able to compare the file from this week to the file from last week. I don't know if this space needs to be deleted but I was planning on doing a compare on the current file and the file named filename_(macro-7). If there is an easier way to do this please let me know!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Sounds like you want use the value of macro variable to construct a filename?

So if your macro variable has the value 21074 and you want to interpret that as a date and generate a human readable string that you could include as part of the filename you need to use a FORMAT.  I would recommend either YYMMDDD10. (2017-09-12) or YYMMDDN8. (20170912) so that your resulting filenames will sort in chronological order.

Perhaps you can apply the format earlier so that the macro variable already looks like the string you want. Or else use the %SYSFUNC() to call the PUTN() function to apply the format to the value.

 

%let date=21074;
%let filename=filename_%sysfunc(putn(&date,yymmddn8.)).xlsx;
proc export file="&filename" ....

 

View solution in original post

2 REPLIES 2
ballardw
Super User

You kind of need to show the existing code you are using/ trying. The are many ways this might be accomplished and knowing what you start with will make responses much more useful.

 

Post code into a code box opened using the forum's {I} or "running man" icons to preserve layout.

 

If instead of 21074 you want something related to 12SEP2017 then somewhere you need to use the proper display format for the value, which you have not provided.

Tom
Super User Tom
Super User

Sounds like you want use the value of macro variable to construct a filename?

So if your macro variable has the value 21074 and you want to interpret that as a date and generate a human readable string that you could include as part of the filename you need to use a FORMAT.  I would recommend either YYMMDDD10. (2017-09-12) or YYMMDDN8. (20170912) so that your resulting filenames will sort in chronological order.

Perhaps you can apply the format earlier so that the macro variable already looks like the string you want. Or else use the %SYSFUNC() to call the PUTN() function to apply the format to the value.

 

%let date=21074;
%let filename=filename_%sysfunc(putn(&date,yymmddn8.)).xlsx;
proc export file="&filename" ....

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1168 views
  • 1 like
  • 3 in conversation