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
Or simply
data want;
set have;
array ship(7) sun_ship -- sat_ship;
correct_ship = ship(weekday(date_ship));
run;
PG
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;
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;
Or simply
data want;
set have;
array ship(7) sun_ship -- sat_ship;
correct_ship = ship(weekday(date_ship));
run;
PG
better.
very nice
I love this solution.
Great work.
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;
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.
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.