BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Stalk
Pyrite | Level 9

I've a dataset that has wrong dates created off of a excel drag function. How can I compare and identify the dates that are exactly one day apart in the sequence to alert the team?

Thank you

ProductID Date_shipped
P3456 10/2/2023
R2342 10/3/2023
H9875 10/4/2023
L5543 10/5/2023
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Use the DIF function.

data want;
  set have;
  days=dif(date_shipped);
run;

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

Use the DIF function.

data want;
  set have;
  days=dif(date_shipped);
run;
Stalk
Pyrite | Level 9

Thank you.

DIF function works, but is there any similar function to DIF to use in Proc SQL?

ERROR: The DIF function is not supported in PROC SQL, it is only valid within the DATA step.

I have all my filters in SQL. Just for handling DIF function I have to recreate the whole dataset and order it again.

 

 

 

Tom
Super User Tom
Super User

@Stalk wrote:

Thank you.

DIF function works, but is there any similar function to DIF to use in Proc SQL?

ERROR: The DIF function is not supported in PROC SQL, it is only valid within the DATA step.

I have all my filters in SQL. Just for handling DIF function I have to recreate the whole dataset and order it again.

 


SQL by its very nature knows nothing about the ORDER of observations so it is a terrible choice to do something like this.

Your second statement makes no sense at all.  How are going to create a new VARIABLE without creating a new dataset, whether you use SQL query or a data step?

Note that you can create views using either PROC SQL code or data step code you want to avoid making multiple physical copies of the data.

Stalk
Pyrite | Level 9
SAS programming is becoming simpler and easy to handle. Way to Go!!!!!!!
Thank you so much for the quick and best solution
ballardw
Super User

Do you have other identification information such as a purchase order/bill of lading/ what have you? It would likely be a good idea to only report these one day increments in the case of  some group identified as such.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 512 views
  • 3 likes
  • 3 in conversation