BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

I want to create a macro variable that calculate YYYY-MM-DD value by the following rule:

If today is Sunday-Friday then 

%let YYYYMMDD =%sysfunc(putn(%sysevalf(%sysfunc(today())-1), YYMMDD10.));
 

If today is Saturday then 
%let YYYYMMDD =%sysfunc(putn(%sysevalf(%sysfunc(today())-2), YYMMDD10.));
 

What is the way to do it please?

 

4 REPLIES 4
LinusH
Tourmaline | Level 20

You can use the weekday() function together with %IF logic.

Data never sleeps
yabwon
Onyx | Level 15

Try this:

%let yyyymmdd = %sysfunc(int(%sysevalf(%sysfunc(today())-1-(%sysfunc(weekday(%sysfunc(today())))=1))),yymmdd10.);

%put &=yyyymmdd.;

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



yabwon
Onyx | Level 15

Or with FCMP, which is easier to read and modify:

proc FCMP outlib=work.f.p;
  function fff();
    return( today()-1-(weekday(today())=1) );
  endsub;
run;
options append=(cmplib=work.f);

%let yyyymmdd=%sysfunc(fff(),yymmdd10.);
%put &=yyyymmdd.;

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



ballardw
Super User

Generic style comment: If the macro variable is to ever be used in comparisons with date values or calculations then do not format it.

The time to use formatted macro date values is for text that humans read such as title statements or possibly filenames.

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
  • 4 replies
  • 318 views
  • 5 likes
  • 4 in conversation