BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Sukhi1
Calcite | Level 5

Hi all, I want to generate a program which will work as per my SLA time. I have a created a format which will tell if a particular date is fall in holiday/weekend. Here is the data I want to print excluding weekend and holiday. my program will run 4 times a day ,7AM , 11AM, 2PM and 4PM. each time I want output like below. for date 18/07/23. either I need 14 row or 17 row 

               7AM                                            11AM                                         2PM                                                   4PM


18/07/23     08:00AM                18/07/23     11:00AM              18/07/23     02:00PM       18/07/23     04:00PM 
17/07/23     04:00PM                 18/07/23     10:00AM             18/07/23     01:00PM         18/07/23     03:00PM 
17/07/23     03:00PM                 18/07/23     09:00AM            18/07/23     12:00PM         18/07/23     02:00PM 
17/07/23     02:00PM                 18/07/23     08:00AM           18/07/23     11:00AM          18/07/23     01:00PM 
17/07/23     01:00PM                  17/07/23     04:00PM             18/07/23     10:00AM       18/07/23     12:00PM 
17/07/23     12:00PM                  17/07/23     03:00PM              18/07/23     09:00AM      18/07/23     11:00AM 
17/07/23     11:00AM                   17/07/23     02:00PM              18/07/23     08:00AM      18/07/23     10:00AM 
17/07/23     10:00AM                  17/07/23     01:00PM               17/07/23     04:00PM      18/07/23     09:00AM 
17/07/23     09:00AM                 17/07/23     12:00PM                17/07/23     03:00PM      18/07/23    08:00AM  
17/07/23     08:00AM                 17/07/23     11:00AM                17/07/23     02:00PM      17/07/23     04:00PM 
14/07/23    04:00PM                  17/07/23     10:00AM             17/07/23     01:00PM        17/07/23     03:00PM 
14/07/23     03:00PM                 17/07/23     09:00AM             17/07/23     12:00PM        17/07/23     02:00PM 
14/07/23     02:00PM                  17/07/23     08:00AM             17/07/23     11:00AM        17/07/23     01:00PM 
14/07/23     01:00PM                   14/07/23     04:00PM             17/07/23     10:00AM      17/07/23     12:00PM 


Please help me create this.

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Thank you for changing the subject line. This helps everyone.

 

You didn't say this in your problem description, but your data implies that the results cannot be on a Saturday or Sunday? Is that correct? If so, please state conditions clearly in the problem description from now on.


Try this:

 

data what_times;
    now=datetime();
    nearest_hour=dhms(datepart(now),hour(timepart(now)),0,0);
    /* Loop and output hours and dates */
    count=0;
    this_hour=nearest_hour;
    do while(count<=14);
        this_hour=intnx('hour',this_hour,-1,'b');
        if 8<=hour(timepart(this_hour))<=16 /* Only output hours 8 through 16 */
            and weekday(datepart(this_hour)) not in (1,7) /* Only output if day of week is 2-6 (Monday thru Friday) */
            then do; 
            output;
            count=count+1;
        end;
    end;    
    format nearest_hour this_hour datetime16.;
run;

  

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Please go back and edit your post and change the subject line to something that actually briefly describes the problem. This helps everyone find posts of interest. If every post had a subject of "sas programming", no one would be able to find posts of interest and the community would be much less useful.

--
Paige Miller
ballardw
Super User

Please don't make us count rows to determine what is needed, list or highlight the text somehow, I'm too lazy to count. And why either row 14 or 17? Programs need to have a pretty clear description of the requirement to create should be.

 

I have a hard time understanding what you expect. You talk about holiday/weekday but those would not change if the program runs at different times of a day.

 

If by a 'format which will tell if a particular date is fall in holiday/weekend' you mean something created in Proc Format then it likely wouldn't hurt to share that with us.

Which Holidays? Holidays are to some extent national in nature. 

You have not even shared if those supposed values are a single variable, multiple variables or what. Where doe they come from?

I suspect that your problem discussion is missing a detail or two of you have and what you are expecting a program to generate.

 

General comment on discussing dates: Do not use 2-digit dates. I am not sure if you are showing values for 23 July 2018 or  18 July 2023.

 

PaigeMiller
Diamond | Level 26

Thank you for changing the subject line. This helps everyone.

 

You didn't say this in your problem description, but your data implies that the results cannot be on a Saturday or Sunday? Is that correct? If so, please state conditions clearly in the problem description from now on.


Try this:

 

data what_times;
    now=datetime();
    nearest_hour=dhms(datepart(now),hour(timepart(now)),0,0);
    /* Loop and output hours and dates */
    count=0;
    this_hour=nearest_hour;
    do while(count<=14);
        this_hour=intnx('hour',this_hour,-1,'b');
        if 8<=hour(timepart(this_hour))<=16 /* Only output hours 8 through 16 */
            and weekday(datepart(this_hour)) not in (1,7) /* Only output if day of week is 2-6 (Monday thru Friday) */
            then do; 
            output;
            count=count+1;
        end;
    end;    
    format nearest_hour this_hour datetime16.;
run;

  

--
Paige Miller
Sukhi1
Calcite | Level 5
Thank you so much. This what I was looking for. You can't believe how much you helped me by doing this. Thanks again

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1045 views
  • 0 likes
  • 3 in conversation