DATA Step, Macro, Functions and more

INTNX and Macro Variable: Returning Date Of Last Saturday All I need to program a macro variabl

Reply
Frequent Contributor
Posts: 101

INTNX and Macro Variable: Returning Date Of Last Saturday All I need to program a macro variabl

Hi All,

 

 I need to program a macro variable which returns the last Saturday of today(). Please see below what I have so far.  I’m having a trouble nailing down the syntax.

 

 Thanks!

 

 

%let today=%sysfunc(today());
%let sat =%sysfunc(intnx(weekday /*Is weekday the correct intnx option*/,(&today),/*NOT SURE what value to put here*/),date9.);
%put &sat ;
Respected Advisor
Posts: 3,156

Re: INTNX and Macro Variable: Returning Date Of Last Saturday All I need to program a macro variab

Posted in reply to RobertNYC
%let last_sat=%sysfunc(intnx(week.7,%sysfunc(today()),0,b),date9.);

%put last_sat=&last_sat ;
Super User
Posts: 7,866

Re: INTNX and Macro Variable: Returning Date Of Last Saturday All I need to program a macro variab

[ Edited ]
Posted in reply to RobertNYC

Before engaging in macro programming, solve your issue with a data step first.

Important to know: weekday() returns 1 for Sunday (2 for Monday, and so on), so subtracting the weekday() result from a SAS date value will give you the immediately previous Saturday. Keep in mind that SAS date values are just a count of days from a given starting date.

data _null_;
sat = today() - weekday(today());
put sat=;
put sat= date9.;
run;

Note how the raw value of sat looks.

Now lets put that logic into a macro statement:

%let sat=%eval(%sysfunc(today()) - %sysfunc(weekday(%sysfunc(today()))));
%put sat=&sat;

And you'll get the same (technical) result.

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 2 replies
  • 111 views
  • 0 likes
  • 3 in conversation