Help using Base SAS procedures

How can I determine if shipment date was done on shipment date?

Accepted Solution Solved
Reply
Regular Contributor
Posts: 240
Accepted Solution

How can I determine if shipment date was done on shipment date?

Hi I have a data set that looks like this

ID        sunship mon ship tue ship wed ship Thursday ship  fri ship sat ship.   Date ship

7918.     0.           1.               0.          1.                      0.           0.          0.         05/01/13

1234.     1.           0.               0.           0.                      1.            0.         0.          05/03/13

the ship is date of week there is a shipment   Date ship is actual day the ship happen. What I would like is to determine if was ship on correct date  for example 05/01/13 was. Correct because it was done on a Wednesday . the 05/03/13 incorrect on wrong day it was on a Friday ....

Thank you again for your assistance


Accepted Solutions
Solution
‎05-07-2013 10:26 PM
Respected Advisor
Posts: 4,659

Re: How can I determine if shipment date was done on shipment date?

Or simply

data want;

set have;

array ship(7) sun_ship -- sat_ship;

correct_ship = ship(weekday(date_ship));

run;

PG

PG

View solution in original post


All Replies
Super Contributor
Posts: 578

Re: How can I determine if shipment date was done on shipment date?

how about something like this:

proc sql;

create table work.incorrect_shipment_dates as

select

     *

from

     work.have

where

     not case weekday(date_ship)

          when 1 then sunship

          when 2 then monship

          ..

          when 7 then Satship

end;

quit;

Super User
Posts: 17,912

Re: How can I determine if shipment date was done on shipment date?

The weekday function in SAS will give you the weekday in 1 to 7. 

Then you can check if your shipped day is 1 on that day.

You have two 1s for the 1st one example so not sure how you want to handle that.

data want;

set have;

array ship(7) sun_ship-sat_ship;

weekday_shipped=weekday(date_ship);

if ship(weekday_shipped)=1 then correct_ship=1;

else correct_ship=0;

run;

Solution
‎05-07-2013 10:26 PM
Respected Advisor
Posts: 4,659

Re: How can I determine if shipment date was done on shipment date?

Or simply

data want;

set have;

array ship(7) sun_ship -- sat_ship;

correct_ship = ship(weekday(date_ship));

run;

PG

PG
Super Contributor
Posts: 578

Re: How can I determine if shipment date was done on shipment date?

better.

Contributor
Posts: 64

Re: How can I determine if shipment date was done on shipment date?

very nice

Super Contributor
Posts: 297

Re: How can I determine if shipment date was done on shipment date?

I love this solution.

Great work.

Super Contributor
Posts: 275

Re: How can I determine if shipment date was done on shipment date?

data have;

input id ship_sun ship_mon  ship_tue  ship_wed  ship_thu  ship_fri  ship_sat  ship_date mmddyy10.;

format ship_date date9.;

cards;

7918     0   0   0   1  0  1  0  05/01/13

1234     1   0   0   0  1  0  0  05/03/13

;

run;

data want(drop=day);

  set have;

  array weekdays ship_sun--ship_sat;

      do over weekdays;

            if weekdays=1 then do;

                day=scan(vname(weekdays),-1,'_');

                  if lowcase(put(ship_date,weekdate3.))=day then yes_ship=day;

              end;

         end;

run;

proc print;

run;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 271 views
  • 8 likes
  • 7 in conversation