BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
BobbyG0627
Fluorite | Level 6

I have searched all kinds of website for the answers and none of the examples I am finding work.

I hope someone has the answer....

I assign a date at the beginning of my program

%let FromDate=01JUN2022;
%let ToDate=31JUL2022;

I reference it all throughout the program with no issues.

When it comes time to produce the excel output though it only comes out in sas date format, I need it in mmddyy10. format

BobbyG0627_0-1660081359679.png

this is the code sample that produced the above...


ODS EXCEL FILE="&flname." OPTIONS(SHEET_NAME="My Sheet" EMBEDDED_TITLES="YES" FROZEN_HEADERS="3" AUTOFILTER="ALL" ); RUN; TITLE j=l "My Report"; TITLE2 j=l "&FromDate - &ToDate.";; RUN;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Macro variables, such as you create, are TEXT. As such the only "format" that applies is the $ format for literal text.

You would need to create a second macro variable for use in the Title.

 

If you don't want to manually create the other value here is one way using what your have entered

%let FromDate=01JUN2022;

%let Titlefrom = %sysfunc(putn("&fromdate."d,mmddyy10.));

You could place all of that %sysfunc code directly into the Title2 statement but it can make harder to read code. Plus if you end up wanting that value somewhere else you would have the same code in multiple places.

View solution in original post

4 REPLIES 4
ballardw
Super User

Macro variables, such as you create, are TEXT. As such the only "format" that applies is the $ format for literal text.

You would need to create a second macro variable for use in the Title.

 

If you don't want to manually create the other value here is one way using what your have entered

%let FromDate=01JUN2022;

%let Titlefrom = %sysfunc(putn("&fromdate."d,mmddyy10.));

You could place all of that %sysfunc code directly into the Title2 statement but it can make harder to read code. Plus if you end up wanting that value somewhere else you would have the same code in multiple places.

BobbyG0627
Fluorite | Level 6

Thank you!!! this was exactly what i needed, I have several outputs so this was exactly what i needed

thank you!

Reeza
Super User
TITLE2 j=l "%sysfunc(inputn(&FromDate, date9.), mmddyy10.) - %sysfunc(inputn(&ToDate, date9.), mmddyy10.)";

Here's a great, but longer and in depth, reference for dates and times in SAS
https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/...

 


@BobbyG0627 wrote:

I have searched all kinds of website for the answers and none of the examples I am finding work.

I hope someone has the answer....

I assign a date at the beginning of my program

%let FromDate=01JUN2022;
%let ToDate=31JUL2022;

I reference it all throughout the program with no issues.

When it comes time to produce the excel output though it only comes out in sas date format, I need it in mmddyy10. format

BobbyG0627_0-1660081359679.png

this is the code sample that produced the above...


ODS EXCEL FILE="&flname." OPTIONS(SHEET_NAME="My Sheet" EMBEDDED_TITLES="YES" FROZEN_HEADERS="3" AUTOFILTER="ALL" ); RUN; TITLE j=l "My Report"; TITLE2 j=l "&FromDate - &ToDate.";; RUN;

 


 

PaigeMiller
Diamond | Level 26
%let FromDate=01JUN2022;
%let ToDate=31JUL2022;

 

These are not in MMDDYY10. appearance. You have to change the appearance of this macro variable value in order to get MMDDYY10.

 

data _null_;
    call symputx('fromdate1',put("&fromdate"D,mmddyy10.));
run;

 

and then later use &FROMDATE1 in TITLE2. Of course, you would perform the same conversion on &TODATE.

 

 

--
Paige Miller

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!
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
  • 4 replies
  • 716 views
  • 0 likes
  • 4 in conversation