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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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