BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AhmedAl_Attar
Ammonite | Level 13

Try this new modified version of the code, I have added a different city, so you can see how the code would behave with different time intervals, and you should be able to take it from here.....

 

data have;
    length    state $2
        city $10        
        fmtname $7
        start 8
        label $5
        hour 4
        minute 4;
    input state city fmtname start :date9. label hour minute;
    format start date9. label $5.;
    datalines;
MD Baltimore sunrise 17Jan2017 07:24 7 24
MD Baltimore sunset 17Jan2017 17:10 17 10
DE Dover sunrise 13JUL2017 04:47 4 47
DE Dover sunset 13JUL2017 19:28 19 28
;
run;

data want(drop=i);
    set have;
    array hours {24} 4 hour_0-hour_23;
    format hour_: BEST8.4;
    
    /* Set all Hours to 0 */
    do i=1 to dim(hours);
        hours[i]=1;
    end;

    if (fmtname='sunrise') then
        /* Assign the Subsequent Hours the factors (minutes/60) */
        do i=(hour+2) to (12+hour-1);
            hours[i]=minute/60;
        end;
    else if (fmtname='sunset') then
    do;
        /* Assign the Hours prior 8:00 am the factors (minutes/60) */
        do i=8 to 1 by -1;
            hours[i]=minute/60;
        end;
        /* Assign the Subsequent Hours the factors (minutes/60) */
        do i=(hour+2) to dim(hours);
            hours[i]=minute/60;
        end;

    end;
    output;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 15 replies
  • 19333 views
  • 1 like
  • 5 in conversation