BookmarkSubscribeRSS Feed
mcrum1
Calcite | Level 5

Hello!

I started this new job in the middle of February and this is my first time using SAS. 'm trying to create macro dates in different formats for a program that we run monthly at our company. This is what I've come up with so far. It runs fine, but I'm unsure if this is the most efficient way to create the dates and with the different formats. Any advice would be greatly appreciated! Thank you!!

DATA Dates1;

       Rundate = INTNX('DAY', TODAY(), 0, 'B');  /* Today */

       MC = INTNX('MONTH', rundate, 0, 'B');  /* Month Current*/

       MP = INTNX('MONTH', rundate, -1, 'B'); /* Month Past*/

/* FORMAT DATE9 */

       CALL SYMPUT ('MC_DATE9',  CATS(PUT(MC,  DATE9.)));

       CALL SYMPUT ('MP_DATE9',  CATS(PUT(MP,  DATE9.)));

/* FORMAT DATE11 */

       CALL SYMPUT ('MC_DATE11',  CATS(PUT(MC,  DATE11.)));

       CALL SYMPUT ('MP_DATE11',  CATS(PUT(MP,  DATE11.)));

/* FORMAT YYMMN6 */

       CALL SYMPUT ('MC_YYMMN6',  CATS(PUT(MC,  YYMMN6.)));

       CALL SYMPUT ('MP_YYMMN6',  CATS(PUT(MP,  YYMMN6.)));

/* FORMAT QOUTED DATE9 */

       CALL SYMPUT ('MC_QDATE9',  CATS("'",PUT(MC,  DATE9.),"'"));

       CALL SYMPUT ('MP_QDATE9',  CATS("'",PUT(MP,  DATE9.),"'"));

/* FORMAT QOUTED DATE11 */

       CALL SYMPUT ('MC_QDATE11',  CATS("'",PUT(MC,  DATE11.),"'"));

       CALL SYMPUT ('MP_QDATE11',  CATS("'",PUT(MP,  DATE11.),"'"));

/* FORMAT QOUTED YYMMN6 */

       CALL SYMPUT ('MC_QYYMMN6',  CATS("'",PUT(MC,  YYMMN6.),"'"));

       CALL SYMPUT ('MP_QYYMMN6',  CATS("'",PUT(MP,  YYMMN6.),"'"));

              put MC     = DATE11.;   /* Month Current  */

              put MP     = DATE11.;   /* Month Past 1 Date Beginning *

RUN;


3 REPLIES 3
Haikuo
Onyx | Level 15

The following does not use data step, so it seems to be less verbose.

%let mc_date9=%sysfunc(intnx(month,%sysfunc(today()),0,b),date9.);

%put &mc_date9;

Haikuo

Kurt_Bremser
Super User

With Haikuo's method you avoid the messages from the data step.

Aside from that, just put your date-generating code in a separate file and %inc it everywhere you need the dates.

However you do it, this piece of code will not use more than just a few milliseconds, so you should do what feels most readable to you.

Efficiency is a point of consideration when you start dealing with massive data.

mcrum1
Calcite | Level 5

Thank you both for great advice. I am trying to format the dates as in Ha Kui's example just to see the difference. I’m sure I’ll have more questions soon!  

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
  • 3 replies
  • 1058 views
  • 3 likes
  • 3 in conversation