BookmarkSubscribeRSS Feed
Shmuel
Garnet | Level 18

@CamRutherford, I quote your posts:

 

I'd want a macro because I reference these dates a lot 
and: How would I reference each date though?

You should be aware of two different terms: macro program and macro variables.

 

Within a macro program you can generate sas code according to arguments given.

Macro variables can be craeted in various ways: by a datastep or by %let statement.

The last can be either in or out of a macro program.

And be aware that macro variable can be global, available anywhere in your sas session or

local. ie available only inside a specific macro program.

 

In your case, you want several macro variables, each per different date.

You got some posts how to do it by a datastep.

The call symput statement assingns a value to a macro variable.

I quote here my code posted, leaving you to complete more assignments as you like:

data _NULL_;
  /*=== calculate dates ===*/
       dt = today();
       dt_1y = intnx('year',dt,-1,'same');
       dt_3m = intnx('month',dt,-3,'same');
       dt_6m = intnx('month',dt,-6,'same');
       dt_9m = intnx('month',dt,-9,'same');
       dt_fpm =  intnx('month',dt,-1,'beginning');
       dt_lpm =  intnx('month',dt,-1,'end');     /* or = toady() - day(today());  */
 
/*=== assign dates to macro variables ===*/
      call symput('toady',left(dt));
      call symput('dt_1y',left(dt_1y));
call symput('dt_3m',left(dt_3m));
...... /* choose your macro variable names and assign the dates calculated */
run;

%put &today &dt_3y &dt_3m;

Run the code and check the log. The numbers you got is the eqivalent to dates calculated.

 

As to the question how you use it, here is a demo:

data _null_;
  today = &today;
  put today ddmmyy10.;

  dt_1y = &dt_1y;
  put 'today last year = ' dt_1y ddmmyy10.;

   tdr = &dt_3m;
   put 'Today 3Mths ago  = ' tdr date9.;

run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 15 replies
  • 2576 views
  • 0 likes
  • 5 in conversation