SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
LMSSAS
Quartz | Level 8

hello, i was running a report monthly and it is moving to weekly. I am trying to solve for having the end date on this date parameter update automatically weekly (every Monday). the report I run Monday should be  cova_evnt_efcv_dt between '01Jan2021'd and '25Apr2022'd

and the following Monday the dates whould be cova_evnt_efcv_dt between '01Jan2021'd and '02May2022'd

I want the end date to update automaically every Monday for a YTD reprot. Can someone provide guidance with this? 

and cova_evnt_efcv_dt between '01Jan2021'd and '31Mar2022'd

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

At the start of your program

 

%let today=%sysfunc(today());

 

and then later

 

cova_evnt_efcv_dt between '01Jan2021'd and &today

 

--
Paige Miller

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

At the start of your program

 

%let today=%sysfunc(today());

 

and then later

 

cova_evnt_efcv_dt between '01Jan2021'd and &today

 

--
Paige Miller
LMSSAS
Quartz | Level 8
Thank you!!
japelin
Rhodochrosite | Level 12

If the execution is on Monday, how about simply using date function as today?

and cova_evnt_efcv_dt between '01Jan2021'd and date()

Or, if you want to run it as of Monday of this week, you can also do the following code.

data _null_;
  /* monday in this week. If you change the 3rd. parameter from 0 to 1, you can specify next Monday */
  monday= intnx( 'week', date(), 0, 'beginning')+1;
  call symputx('end_date',monday);
run;

 

how to use it.

and cova_evnt_efcv_dt between '01Jan2021'd and &end_date

 

 

PaigeMiller
Diamond | Level 26

@japelin wrote:

If the execution is on Monday, how about simply using date function as today?

and cova_evnt_efcv_dt between '01Jan2021'd and date()

 


I like your answer better than mine!

 

... unless you need today's date in titles, in which case you would need the macro variable approach (and you would have to apply a format to it if you were going to use it in the title)

--
Paige Miller
maguiremq
SAS Super FREQ

Are you always looking a year back?

 

data want;
	cova_evnt_efcv_dt = '01JAN1960'd; output;
	cova_evnt_efcv_dt = '01JAN2021'd; output;
	cova_evnt_efcv_dt = '21APR2022'd; output;
	cova_evnt_efcv_dt = '20APR2022'd; output;
	cova_evnt_efcv_dt = '23JAN2020'd; output;
	cova_evnt_efcv_dt = '01JAN2021'd; output;
	cova_evnt_efcv_dt = '30MAR2022'd; output;
	cova_evnt_efcv_dt = '21MAR2022'd; output;
	cova_evnt_efcv_dt = '28JUN2022'd; output;
	format cova_evnt_efcv_dt date9.;
run;

proc sql;
	select
				*
	from
				want
	where
				cova_evnt_efcv_dt between mdy(1, 1, year(today()) - 1) and today();
quit;

`today()` would be based on when you run the report. If you automated it every Monday, you wouldn't have to look at it anymore.

LMSSAS
Quartz | Level 8
No, I'm not always looking a year back. it will be YTD starting every year. Unless the customer changes their mind, which is always possible.

thank you!
PaigeMiller
Diamond | Level 26

@LMSSAS wrote:
No, I'm not always looking a year back. it will be YTD starting every year. Unless the customer changes their mind, which is always possible.

thank you!

In that case, use this (giving credit to @japelin )

 

and cova_evnt_efcv_dt between intnx('year',today(),0,'b') and today()
--
Paige Miller

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1272 views
  • 2 likes
  • 4 in conversation