<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: IF then with TIMEAMPM data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IF-then-with-TIMEAMPM-data/m-p/598591#M172637</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
   value shift
      '00:00:00't -&amp;lt; '07:00:00't = 'OVERNIGHT'
      '07:00:00't -&amp;lt; '15:00:00't = 'AM'
      '15:00:00't -&amp;lt; '23:00:00't = 'PM'
      '23:00:00't -&amp;lt; '23:59:59.9999999't = 'OVERNIGHT' /* only needed if you have fractional time */
   ;
run;

data have;
   do time='00:00:00't to '23:59:59't /* by (60*60) */ ;
      shift=put(time,shift.);
      output;
   end;

   * edge case, not needed if you don't have fractional time ;
   time='23:59:59.999't;
   shift=put(time,shift.);
   output;
   format time time15.6;
run;

proc sort data=have;
   by shift time;
run;

data review;
   set have;
   by shift time;
   if first.shift or last.shift or time in ('23:00:00't,'00:00:00't);
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 23 Oct 2019 02:52:22 GMT</pubDate>
    <dc:creator>ScottBass</dc:creator>
    <dc:date>2019-10-23T02:52:22Z</dc:date>
    <item>
      <title>IF then with TIMEAMPM data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-then-with-TIMEAMPM-data/m-p/598520#M172603</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not having much luck re-coding my time variable. What I would like is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;7AM-3PM = 'AM'&lt;/P&gt;&lt;P&gt;3PM-11PM = 'PM'&lt;/P&gt;&lt;P&gt;11PM-7AM = 'OVERNIGHT'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have data that looks like this&amp;nbsp;&lt;/P&gt;&lt;P&gt;HAVE&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;TIME&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;102028027&lt;/TD&gt;&lt;TD&gt;4:00:00 AM&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;102028032&lt;/TD&gt;&lt;TD&gt;6:45:00 AM&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;102028088&lt;/TD&gt;&lt;TD&gt;3:15:00 PM&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;102028089&lt;/TD&gt;&lt;TD&gt;9:00:00 AM&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;102028049&lt;/TD&gt;&lt;TD&gt;1:30:00 PM&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;WANT&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;TIME&lt;/TD&gt;&lt;TD&gt;SHIFT&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;102028027&lt;/TD&gt;&lt;TD&gt;4:00:00 AM&lt;/TD&gt;&lt;TD&gt;Overnight&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;102028032&lt;/TD&gt;&lt;TD&gt;6:45:00 AM&lt;/TD&gt;&lt;TD&gt;Overnight&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;102028088&lt;/TD&gt;&lt;TD&gt;3:15:00 PM&lt;/TD&gt;&lt;TD&gt;PM&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;102028089&lt;/TD&gt;&lt;TD&gt;9:00:00 AM&lt;/TD&gt;&lt;TD&gt;AM&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;102028049&lt;/TD&gt;&lt;TD&gt;1:30:00 PM&lt;/TD&gt;&lt;TD&gt;AM&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2019 20:31:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-then-with-TIMEAMPM-data/m-p/598520#M172603</guid>
      <dc:creator>hwangnyc</dc:creator>
      <dc:date>2019-10-22T20:31:44Z</dc:date>
    </item>
    <item>
      <title>Re: IF then with TIMEAMPM data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-then-with-TIMEAMPM-data/m-p/598522#M172605</link>
      <description>&lt;P&gt;Is time an actual SAS Time valie i.e. numeric?&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2019 20:35:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-then-with-TIMEAMPM-data/m-p/598522#M172605</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-22T20:35:37Z</dc:date>
    </item>
    <item>
      <title>Re: IF then with TIMEAMPM data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-then-with-TIMEAMPM-data/m-p/598524#M172606</link>
      <description>&lt;P&gt;Good question, it's numeric with the timeampm format.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2019 20:38:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-then-with-TIMEAMPM-data/m-p/598524#M172606</guid>
      <dc:creator>hwangnyc</dc:creator>
      <dc:date>2019-10-22T20:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: IF then with TIMEAMPM data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-then-with-TIMEAMPM-data/m-p/598526#M172608</link>
      <description>&lt;P&gt;Do something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID TIME : time9.;
format TIME time9.;
datalines;
102028027 4:00:00AM
102028032 6:45:00AM
102028088 3:15:00PM
102028089 9:00:00AM
102028049 1:30:00PM
;

proc format;
   value ampm 
      '07:00't &amp;lt;- '15:00't = 'Overnight'
      '15:00't &amp;lt;- '23:00't = 'PM'
      other                = 'AM';
run;

data want;
   set have;
   shift=put(TIME, ampm.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ID          TIME       shift 
102028027   4:00:00    AM 
102028032   6:45:00    AM 
102028088   15:15:00   PM 
102028089   9:00:00    Overnight 
102028049   13:30:00   Overnight 
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2019 20:46:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-then-with-TIMEAMPM-data/m-p/598526#M172608</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-22T20:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: IF then with TIMEAMPM data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-then-with-TIMEAMPM-data/m-p/598534#M172611</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;  
infile cards dsd dlm=","; 
  input ID $ TIME : TIME11.;
  format TIME TIMEAMPM11.;
  cards ;                       
102028027, 4:00:00 AM,
102028032, 6:45:00 AM,
102028088, 3:15:00 PM,
102028089, 9:00:00 AM,
102028049, 1:30:00 PM
;
run;

data want;
set have;
IF '15:00:00't &amp;lt;= TIME &amp;lt;= '22:59:59't THEN SHIFT = 'PM ';
IF '07:00:00't &amp;lt;= TIME &amp;lt;= '14:59:59't THEN SHIFT = 'AM ';
IF '23:00:00't &amp;lt;= TIME &amp;lt;= '23:59:59't THEN SHIFT = 'Overnight';
IF '00:00:00't &amp;lt;= TIME &amp;lt;= '06:59:59't THEN SHIFT = 'Overnight';
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's what I came up with. I wasn't able to come up with an alternative for the overnight time maybe someone can expand on that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2019 21:16:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-then-with-TIMEAMPM-data/m-p/598534#M172611</guid>
      <dc:creator>Krueger</dc:creator>
      <dc:date>2019-10-22T21:16:15Z</dc:date>
    </item>
    <item>
      <title>Re: IF then with TIMEAMPM data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-then-with-TIMEAMPM-data/m-p/598548#M172615</link>
      <description>&lt;P&gt;Do you have missing values that need to be considered?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
IF '15:00:00't &amp;lt;= TIME &amp;lt;= '22:59:59't THEN SHIFT = 'PM ';
ELSE IF '07:00:00't &amp;lt;= TIME &amp;lt;= '14:59:59't THEN SHIFT = 'AM ';
ELSE IF not missing(time) then SHIFT = 'Overnight';

RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/295821"&gt;@Krueger&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;  
infile cards dsd dlm=","; 
  input ID $ TIME : TIME11.;
  format TIME TIMEAMPM11.;
  cards ;                       
102028027, 4:00:00 AM,
102028032, 6:45:00 AM,
102028088, 3:15:00 PM,
102028089, 9:00:00 AM,
102028049, 1:30:00 PM
;
run;

data want;
set have;
IF '15:00:00't &amp;lt;= TIME &amp;lt;= '22:59:59't THEN SHIFT = 'PM ';
IF '07:00:00't &amp;lt;= TIME &amp;lt;= '14:59:59't THEN SHIFT = 'AM ';
IF '23:00:00't &amp;lt;= TIME &amp;lt;= '23:59:59't THEN SHIFT = 'Overnight';
IF '00:00:00't &amp;lt;= TIME &amp;lt;= '06:59:59't THEN SHIFT = 'Overnight';
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's what I came up with. I wasn't able to come up with an alternative for the overnight time maybe someone can expand on that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2019 22:10:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-then-with-TIMEAMPM-data/m-p/598548#M172615</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-22T22:10:22Z</dc:date>
    </item>
    <item>
      <title>Re: IF then with TIMEAMPM data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-then-with-TIMEAMPM-data/m-p/598552#M172618</link>
      <description>&lt;P&gt;I wasn't chaining ELSE IF which was my problem, instead I was trying...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IF THEN 1...&lt;/P&gt;&lt;P&gt;IF THEN 2...&lt;/P&gt;&lt;P&gt;ELSE 3...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and it was giving me 1 OR 3 not 1, 2 OR 3.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2019 22:19:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-then-with-TIMEAMPM-data/m-p/598552#M172618</guid>
      <dc:creator>Krueger</dc:creator>
      <dc:date>2019-10-22T22:19:19Z</dc:date>
    </item>
    <item>
      <title>Re: IF then with TIMEAMPM data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-then-with-TIMEAMPM-data/m-p/598591#M172637</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
   value shift
      '00:00:00't -&amp;lt; '07:00:00't = 'OVERNIGHT'
      '07:00:00't -&amp;lt; '15:00:00't = 'AM'
      '15:00:00't -&amp;lt; '23:00:00't = 'PM'
      '23:00:00't -&amp;lt; '23:59:59.9999999't = 'OVERNIGHT' /* only needed if you have fractional time */
   ;
run;

data have;
   do time='00:00:00't to '23:59:59't /* by (60*60) */ ;
      shift=put(time,shift.);
      output;
   end;

   * edge case, not needed if you don't have fractional time ;
   time='23:59:59.999't;
   shift=put(time,shift.);
   output;
   format time time15.6;
run;

proc sort data=have;
   by shift time;
run;

data review;
   set have;
   by shift time;
   if first.shift or last.shift or time in ('23:00:00't,'00:00:00't);
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Oct 2019 02:52:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-then-with-TIMEAMPM-data/m-p/598591#M172637</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-10-23T02:52:22Z</dc:date>
    </item>
  </channel>
</rss>

