BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sotarkadin
Calcite | Level 5

Currently I have a report I run where I filter based on the date and 8 days back.

where a.action_dt > (date - INTERVAL '8' DAY)

I am looking to change this that the action_dt will always be between Monday and Sunday of the previous week no matter when I run the report that week.

Desired Result:

where a.action_dt between &monday and &sunday

I am just not sure how to get those variables to always be the previous dates I need based on whatever day I run the report.

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

You need a shifted time interval.

data _null_;
    ref=today();
    monday = intnx(
'week1.2',ref,-1,'Begin');
    sunday = intnx('week1.2',ref,-1,'End');
    format _all_ weekdate.;
   
put (_all_)(=/);
    run;

ref=Tuesday, May
26, 2015
monday=Monday, May
18, 2015
sunday=Sunday, May
24, 2015

View solution in original post

3 REPLIES 3
data_null__
Jade | Level 19

You need a shifted time interval.

data _null_;
    ref=today();
    monday = intnx(
'week1.2',ref,-1,'Begin');
    sunday = intnx('week1.2',ref,-1,'End');
    format _all_ weekdate.;
   
put (_all_)(=/);
    run;

ref=Tuesday, May
26, 2015
monday=Monday, May
18, 2015
sunday=Sunday, May
24, 2015
Sotarkadin
Calcite | Level 5

Thank you so much that relly helped. I do have another question on this same report I am working on.  It's a little different but still revolves around day of week.  I am not sure if I shoudl start another discussion or can it just be answered here.

I am currently joining two tables based on the data an action occurs:

proc sql;

create table ltr_chck as

select a.cm15, a.case_nbr, a.action_dt, a.frd_action, a.user_id_cd, b.action_Dt as ltr_action, b.frd_action as ltr_action

from value_actions_dedup a

left join letter_actions_dedup b

on a.action_dt = b.action_dt

where a.cm15 = b.cm15

and a.user_id_cd NE 'XXXXX';

run;

I am looking to specify the join for different date criteria.   If the a.action_dt is a Friday, Saturday or Sunday, then it needs to look for the b.action_dt of the Monday after.

on a.action_dt = b.action_dt

or if a.ction_dt is Fri, Sat, Sun then b.action_dt = Mon after

data_null__
Jade | Level 19

If you have another question start another thread.  Include some sample data that is representative of the join you want to do.  Show have and want.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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