BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BETO
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

7 REPLIES 7
DBailey
Lapis Lazuli | Level 10

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;

Reeza
Super User

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;

PGStats
Opal | Level 21

Or simply

data want;

set have;

array ship(7) sun_ship -- sat_ship;

correct_ship = ship(weekday(date_ship));

run;

PG

PG
Scott_Mitchell
Quartz | Level 8

I love this solution.

Great work.

slchen
Lapis Lazuli | Level 10

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;

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 7 replies
  • 1027 views
  • 8 likes
  • 7 in conversation