BookmarkSubscribeRSS Feed
Sandy
Calcite | Level 5

Hi All,

Based on data could anyone assist me - making program that contains

test_date closest to delivery_date.

delivery_date         test_date   

11/16/2011                21/nov/2011      

                               10/nov/2011

                               15/oct/2010

Thanks in advance

2 REPLIES 2
Haikuo
Onyx | Level 15

Hi, I figure you should have an 'id' variable in this case, but if you don't, feel free to take it out:

proc sql;

  create table want as

     select distinct a.* from have a, have b

   where a.id=b.id

     group by a.id /*I assume you should have one*/, b.delivery_date

   having abs(b.test_date-a.delivery_date)=min(abs(a.delivery_date-b.test_date));

quit;

Haikuo

Sandy
Calcite | Level 5

I have a variable delivery_date with one observation and test_date with 20 observations. I'd like to find the closest date in test_date to delivery_date by find the minimum absolute difference and retain the minimum value.

When I merge the datasets I only get two observations paired up and get missing values for the rest. Would anyone please explain how to go about this with maybe a do loop or...???

Thank you!

delivery_date
11/16/2011
Test_date
13-Mar-11
10-Apr-11
20-May-11
9-Jun-11
31-Jul-11
17-Aug-11
12-Sep-11
10-Nov-11
11-Oct-11
12-Dec-11
29-Feb-12
13-Mar-13
10-Apr-10
20-May-10
9-Jun-10
21-Jul-11
15-Aug-11
19-Oct-11
21-Nov-11
22-Dec-11

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!

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
  • 2 replies
  • 412 views
  • 0 likes
  • 2 in conversation