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

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

1 ACCEPTED SOLUTION

Accepted Solutions
slchen
Lapis Lazuli | Level 10

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;

View solution in original post

5 REPLIES 5
ballardw
Super User

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?

BETO
Fluorite | Level 6

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

ballardw
Super User

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

slchen
Lapis Lazuli | Level 10

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;

Ksharp
Super User
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

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
  • 5 replies
  • 839 views
  • 3 likes
  • 4 in conversation