BookmarkSubscribeRSS Feed
SASAna
Quartz | Level 8

Hi SAS Users,

 

I wanted some help in finding the current week logic like below.  

 

Logic - get the current week from the Modiefied date and compare it with the current week.

 

    where week(datepart(modified_date)) eq week(today()) 

 

 

data current_week;
set previous_dataset;               ---------->  it has a field  'modified_date'  - a date field.
where week(datepart(modified_date)) eq week(today());
run;

 

Thanks,

Ana

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Exactly what help do you want?

 

Please explain what is not working. Show us a portion of your data. Show us the relevant code and relevant parts of the SASLOG.

--
Paige Miller
Astounding
PROC Star

First a couple of general guidelines ...

 

If you have a date variable, you would not apply DATEPART to it.  DATEPART only applies to a variable that contains a datetime value, to extract the date.

 

The WEEK function finds the week within the year.  So if you compare the WEEK of TODAY() to the WEEK of some other date variable, you could find a match for dates that are a year apart.

 

What is in your existing modified date variable?  Data for every day, or just data for one day per week?  It is conceivable you could use something as simple as:

 

where modified_date > today() - 7;

Reeza
Super User

@SASAna not seeing anything wrong with your code so it's a logic error. To clarify we'll need to see what the variable looks like, what the type is and are you absolutely sure you have data for this week already?

SASAna
Quartz | Level 8

Requirment is to get the current week's work assignments by using the modified_date field.

 

modified_date is datetime field. So i have used datepart function.

 

data current_week;
set previous_dataset;               
where datepart(modified_date) le today() - 7 ;
run;

 

Thanks,

Ana

Astounding
PROC Star

So that's most of the way there.   The comparison "le" is incorrect, as it selects the wrong time period.  Replace it with either > or >=  depending on whether the date from 7 days earlier should be excluded or included.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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