Im working on a table that houses schedule of service by AM or PM
this is how table is formatt
store # M T W TH FR SAT SUN
1. A.
2 P
3. A
i will get a sec table that shows actually deliver timestamp
store. Time
1. 1:23 pm
2. 3:33 pm
3. 9:00 AM
I need to compare 1st table with 2 nd table to determine if the time delivery was made was at am or pm..
in the example I provided the 1st one is out of compliance since it was done at pm when it should be done at am
I am not sure whether this is what you need.
DATA TAB1;
INFILE CARDS TRUNCOVER;
INPUT store (MON TUE WEN THU FRI SAT SUN) ($2.);
CARDS;
1 A . . . . . .
2 . P . . . . .
3 . . . A . . .
;
RUN;
DATA TAB2;
INPUT STORE TIME :&$10.;
CARDS;
1 1:23 pm
2 3:33 pm
3 9:00 AM
;
RUN;
DATA WANT;
IF 0 THEN SET TAB2;
IF _N_=1 THEN DO;
DECLARE HASH H(DATASET:'TAB2');
H.DEFINEKEY('STORE');
H.DEFINEDATA('TIME');
H.DEFINEDONE();
END;
SET TAB1;
ARRAY VAR _CHARACTER_;
IF H.FIND()=0 THEN DO;
DO over VAR;
if NOT MISSING (VAR) THEN DO;
FLAG=(UPCASE(SUBSTR(COMPRESS(TIME,,'KA'),1,1))=VAR);
END;
END;
END;
RUN;
Do your stores have different target times depending on the day of the week? If so, you'll need to provide more details.
Are you reading the time into SAS as actual time values or strings?
THe only target is that some stores need to be Done AM or PM .The second table will have the time is as a date time
So, is the DATETIME a SAS Datetime variable or a string? If a string, what does it look like?
I am not sure whether this is what you need.
DATA TAB1;
INFILE CARDS TRUNCOVER;
INPUT store (MON TUE WEN THU FRI SAT SUN) ($2.);
CARDS;
1 A . . . . . .
2 . P . . . . .
3 . . . A . . .
;
RUN;
DATA TAB2;
INPUT STORE TIME :&$10.;
CARDS;
1 1:23 pm
2 3:33 pm
3 9:00 AM
;
RUN;
DATA WANT;
IF 0 THEN SET TAB2;
IF _N_=1 THEN DO;
DECLARE HASH H(DATASET:'TAB2');
H.DEFINEKEY('STORE');
H.DEFINEDATA('TIME');
H.DEFINEDONE();
END;
SET TAB1;
ARRAY VAR _CHARACTER_;
IF H.FIND()=0 THEN DO;
DO over VAR;
if NOT MISSING (VAR) THEN DO;
FLAG=(UPCASE(SUBSTR(COMPRESS(TIME,,'KA'),1,1))=VAR);
END;
END;
END;
RUN;
DATA TAB1; INFILE CARDS TRUNCOVER; INPUT store (MON TUE WEN THU FRI SAT SUN) ($2.); CARDS; 1 A . . . . . . 2 . P . . . . . 3 . . . A . . . ; RUN; DATA TAB2; INPUT STORE TIME & anydttme.; format time timeampm.; CARDS; 1 1:23 pm 2 3:33 pm 3 9:00 AM ; RUN; options missing=' '; data want; merge tab1 tab2; by store; want= ( cats(of mon--sun)=first(put(time,timeampm3. -l)) ); run;
Xia Keshan
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.