Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 229399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:45:45+00:00 2026-05-11T19:45:45+00:00

I have a macro that creates a timestamp (to append to output file names).

  • 0

I have a macro that creates a timestamp (to append to output file names). However, rather than have to remember what macro variable the macro assigns the value to, I would prefer to assign a macro variable to the result of the macro (if that isn’t circular enough).

%let tms= %tms();

This is the current macro….

%macro tms ;
    %* Create a Timestamp ;
 %let tms_date= %sysfunc(date(),yymmdd10.) ;  %* Todays date ;
 %let tms_time= %sysfunc(time(),time.) ;      %* Current Time ;

    %* Format mmddyyhhmmss ;
 %let tms=_%scan(&tms_date,1)%scan(&tms_date,2)%scan(&tms_date,3)%scan(&tms_time,1,:)%scan(&tms_time,2,:)%scan(&tms_time,3,:) ;

%mend ;

How do you quote this to make it work?
Also, would I just remove the “%let tms=” from the macro?

Also, would the same quoting work for the following ODS assignment statement?

ods Tagsets.excelxp file="&outname.&tms..xml" style= Styles.XLsansPrinter ;

Thanks for taking the time….

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:45:46+00:00Added an answer on May 11, 2026 at 7:45 pm

    A macro with a return value is usually called a macro function. Before the mend statment, if you put an expression/value without a semicolon, it will return the value to the caller. If the return value is in an if-else block, the ; would be necessary.

    Basically, you can do as you suggest and remove the %let tms= from inside the macro. And yes, I do believe it would work with the ods assignment statment.

    %macro tms ;
        %* Create a Timestamp ;
     %let tms_date= %sysfunc(date(),yymmdd10.) ;  %* Todays date ;
     %let tms_time= %sysfunc(time(),time.) ;      %* Current Time ;
    
            %* Format mmddyyhhmmss ;
     _%scan(&tms_date,1)%scan(&tms_date,2)%scan(&tms_date,3)%scan(&tms_time,1,:)%scan(&tms_time,2,:)%scan(&tms_time,3,:) 
    %mend;
    %let tms=%tms;
    %put **&tms**;
    

    As another suggestion, you can simplify the code somewhat by using the compress function insead of the %scan functions like this

    %sysfunc(compress(_&tms_date.&tms_time,"-:"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Excel file that has a bunch of VBA and macro code
I have a macro that creates a new document based on a template stored
I have an excel template that uses a macro to save the file, so
I have a macro that I wrote to just help me with my unit
I have a macro that looks like this: #define coutError if (VERBOSITY_SETTING >= VERBOSITY_ERROR)
I recently inherited a VBA macro that needs to have validation logic added to
I'm writing a Win32 service in C++. I have a custom Assert macro that
I have a 'foreach' macro I use frequently in C++ that works for most
I have an access macro, that I want to run automatically from a batch
I have an Excel 2003 workbook that contains a macro to copy certain of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.