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 (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
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 (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
albribmun
Fluorite | Level 6

I have already found the solution using this: 

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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 11 replies
  • 954 views
  • 7 likes
  • 5 in conversation