BookmarkSubscribeRSS Feed
albribmun
Fluorite | Level 6

Hi,

I would like to be able to select data where the 'send date' of my dataset refers to the last 3 weeks from today.

albribmun_0-1655136353349.png

Thanks.

11 REPLIES 11
Quentin
Super User

Hi,

 

Please show what code you have tried, and describe why it didn't work (did you get an error? did you get a surprising result?).

 

Also, please define your selection criteria more precisely.  Do you want to select all records where FECHA_ENVIO is within 21 days of today's date (the date the program is run)?

 

Perhaps:

if (today() - datepart(fecha_envio)) <=21  ;
The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
Reeza
Super User
where fecha_envio > intnx('dtweek', today(), -3, 'b');

Thinks you should consider - what defines a week? Is it 21 days before exactly or does it start on Sunday's? Does it start at the same times as when you run the report (e.g 10:23) or is at the start of the day (00:00)? You control these choices with the first and last parameter in the INTNX function.
albribmun
Fluorite | Level 6

I have executed the command you say and it does not give me an error but it does not give me the expected result.

 

albribmun_0-1655137904711.pngalbribmun_1-1655137924185.png

 

Reeza
Super User
intnx('dtday', today(), -21, 'b');

Try that one instead
albribmun
Fluorite | Level 6

Not all

albribmun_0-1655192545333.png

Log:

albribmun_1-1655192561424.png

 

 

Kurt_Bremser
Super User

@albribmun wrote:

Not all

 


And as your log tells you, 885 observations met the condition and were read and written to the new dataset.

 

Please do not post pictures. Copy/paste log text to a window opened with this button:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

To supply example data for our use in developing and testing code, use a data step with datalines, and post it as text in a window opened with the "little running man" right next to the one indicated.

Tom
Super User Tom
Super User

Note that TODAY() is just an alias for the DATE() function.

So the function TODAY() returns a DATE value (number of days since 1960).

The DTDAY interval works with DATETIME values (number of seconds since 1960).

If you treat the number of days since 1960 as the number of seconds since 1960 you get some time early on January 1,1960.

 

If you want the current datetime value use the DATETIME() function.

 

albribmun
Fluorite | Level 6

Yes, I want to get all records for all other variables where the date is between the last 3 weeks. The code does not give me error, but the table is not displayed.

 

albribmun_0-1655137449375.png

 

albribmun_1-1655137470299.png

 

 

Quentin
Super User
Can you show the log? It should show the number of records read in, and the number of records written out. It may also show errors, warnings, or bad notes.
The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
albribmun
Fluorite | Level 6

I have already found the solution using this: 

if intck('week', today(), datepart(fecha_envio)) ge -3

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 11 replies
  • 995 views
  • 7 likes
  • 5 in conversation