BookmarkSubscribeRSS Feed
RobertNYC
Obsidian | Level 7

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 ;
2 REPLIES 2
Haikuo
Onyx | Level 15
%let last_sat=%sysfunc(intnx(week.7,%sysfunc(today()),0,b),date9.);

%put last_sat=&last_sat ;
Kurt_Bremser
Super User

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.

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 4435 views
  • 0 likes
  • 3 in conversation