## How to delivery done in the AM/PM

Solved
Regular Contributor
Posts: 240

# How to delivery done in the AM/PM

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

Accepted Solutions
Solution
‎06-26-2014 06:48 PM
Super Contributor
Posts: 275

## Re: How to delivery done in the AM/PM

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;

All Replies
Super User
Posts: 13,508

## Re: How to delivery done in the AM/PM

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?

Regular Contributor
Posts: 240

## Re: How to delivery done in the AM/PM

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

Super User
Posts: 13,508

## Re: How to delivery done in the AM/PM

So, is the DATETIME a SAS Datetime variable or a string? If a string, what does it look like?

Solution
‎06-26-2014 06:48 PM
Super Contributor
Posts: 275

## Re: How to delivery done in the AM/PM

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;

Super User
Posts: 10,766

## Re: How to delivery done in the AM/PM

```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

🔒 This topic is solved and locked.

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

Discussion stats
• 5 replies
• 283 views
• 3 likes
• 4 in conversation