<?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: flag time as 0 and 1 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/flag-time-as-0-and-1/m-p/374203#M276282</link>
    <description>&lt;P&gt;That blog post I linked to shows exactly how. &amp;nbsp;You have to decide whether to truncate (7:20:34 becomes 7:20:00) or round (to 7:21:00).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Easy way to round, adapted from that post:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	t = '07:20:34't;
	t_m = round(t,60); /* nearest minute */
	put t_m= time5.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;A href="http://blogs.sas.com/content/sgf/2017/02/10/truncating-vs-rounding-sas-time-values/" target="_self"&gt;http://blogs.sas.com/content/sgf/2017/02/10/truncating-vs-rounding-sas-time-values/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 08 Jul 2017 23:11:11 GMT</pubDate>
    <dc:creator>ChrisHemedinger</dc:creator>
    <dc:date>2017-07-08T23:11:11Z</dc:date>
    <item>
      <title>flag time as 0 and 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-time-as-0-and-1/m-p/374184#M276277</link>
      <description>&lt;P&gt;Hi -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data set looks like this:&lt;/P&gt;&lt;P&gt;id &amp;nbsp;time&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; 7:20&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; 7:26&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; 8:15&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; 8:40&lt;/P&gt;&lt;P&gt;I want to create a flag and a dummy variable that can label&amp;nbsp;a certain time:&lt;/P&gt;&lt;P&gt;id &amp;nbsp;time &amp;nbsp; flag &amp;nbsp; &amp;nbsp;dummy&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; 7:20 &amp;nbsp; 7:20 &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; 7:26 &amp;nbsp; 7:20 &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; 8:15 &amp;nbsp; 7:20 &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; 8:40 &amp;nbsp; 7:20 &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;My current code is attached below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data flag;
  set data;
  flag = '7:20't;
  if time = flag then dummy = 1;
  else dummy = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This does not work (all value in dummy are zeros). I extracted time from datetime. format, the original time is like&amp;nbsp;&lt;SPAN&gt;17MAR2016 07:20:00, is that the reason?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Not sure how to solve it. &amp;nbsp;Any idea?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks!!!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Jul 2017 17:55:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-time-as-0-and-1/m-p/374184#M276277</guid>
      <dc:creator>panda</dc:creator>
      <dc:date>2017-07-08T17:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: flag time as 0 and 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-time-as-0-and-1/m-p/374185#M276278</link>
      <description>&lt;P&gt;Post the code you used to extract time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Jul 2017 18:10:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-time-as-0-and-1/m-p/374185#M276278</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-08T18:10:09Z</dc:date>
    </item>
    <item>
      <title>Re: flag time as 0 and 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-time-as-0-and-1/m-p/374187#M276279</link>
      <description>&lt;P&gt;This might be an issue of precision and rounding. &amp;nbsp;Do you know that your "7:20" value is exactly 7:20, with no seconds? &amp;nbsp;For a comparison of just hours/minutes, you might want to either truncate or round the values before comparison.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#2196f3"&gt;&lt;SPAN style="background-color: #eaeaea;"&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/51532"&gt;@LeonidBatkhan&lt;/a&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;has a good &lt;A href="http://blogs.sas.com/content/sgf/2017/02/10/truncating-vs-rounding-sas-time-values/" target="_self"&gt;blog post about rounding/truncating time values here&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Sat, 08 Jul 2017 18:28:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-time-as-0-and-1/m-p/374187#M276279</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2017-07-08T18:28:13Z</dc:date>
    </item>
    <item>
      <title>Re: flag time as 0 and 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-time-as-0-and-1/m-p/374201#M276280</link>
      <description>&lt;P&gt;Hi -&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used timepart to extract the time:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set data;
   time = timepart(time);
   format time hhmm5.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks!!&lt;/P&gt;</description>
      <pubDate>Sat, 08 Jul 2017 22:54:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-time-as-0-and-1/m-p/374201#M276280</guid>
      <dc:creator>panda</dc:creator>
      <dc:date>2017-07-08T22:54:46Z</dc:date>
    </item>
    <item>
      <title>Re: flag time as 0 and 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-time-as-0-and-1/m-p/374202#M276281</link>
      <description>&lt;P&gt;Hi -&lt;/P&gt;&lt;P&gt;The original times have seconds in them, like 07:20:34. Not sure how to round all of the times to minutes (07:20:34 -&amp;gt; 07:20:00).&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Jul 2017 22:58:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-time-as-0-and-1/m-p/374202#M276281</guid>
      <dc:creator>panda</dc:creator>
      <dc:date>2017-07-08T22:58:14Z</dc:date>
    </item>
    <item>
      <title>Re: flag time as 0 and 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-time-as-0-and-1/m-p/374203#M276282</link>
      <description>&lt;P&gt;That blog post I linked to shows exactly how. &amp;nbsp;You have to decide whether to truncate (7:20:34 becomes 7:20:00) or round (to 7:21:00).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Easy way to round, adapted from that post:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	t = '07:20:34't;
	t_m = round(t,60); /* nearest minute */
	put t_m= time5.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;A href="http://blogs.sas.com/content/sgf/2017/02/10/truncating-vs-rounding-sas-time-values/" target="_self"&gt;http://blogs.sas.com/content/sgf/2017/02/10/truncating-vs-rounding-sas-time-values/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Jul 2017 23:11:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-time-as-0-and-1/m-p/374203#M276282</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2017-07-08T23:11:11Z</dc:date>
    </item>
    <item>
      <title>Re: flag time as 0 and 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-time-as-0-and-1/m-p/374206#M276283</link>
      <description>&lt;P&gt;That links is very helpful!!&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think if the time is 7:20:45, it should be round to 7:21; and if the time is 7:20:12, it should be round to 7:20, so round function should&amp;nbsp;&lt;/P&gt;&lt;P&gt;work perfectly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!!&lt;/P&gt;</description>
      <pubDate>Sat, 08 Jul 2017 23:25:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-time-as-0-and-1/m-p/374206#M276283</guid>
      <dc:creator>panda</dc:creator>
      <dc:date>2017-07-08T23:25:02Z</dc:date>
    </item>
    <item>
      <title>Re: flag time as 0 and 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-time-as-0-and-1/m-p/374207#M276284</link>
      <description>&lt;P&gt;Of course, if you didn't want to round you could always use:&lt;/P&gt;
&lt;PRE&gt;data data;
  informat time anydtdtm16.;
  input id  time;
  cards;
1   8jul2017:7:20:30
1   8jul2017:7:26:31
2   8jul2017:8:15:31
2   8jul2017:8:40:31
;

data flag;
  set data;
  flag = '7:20't;
  if hour(timepart(time)) eq hour(flag) and minute(timepart(time)) eq minute(flag) then dummy = 1;
  else dummy = 0;
run;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Sat, 08 Jul 2017 23:28:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-time-as-0-and-1/m-p/374207#M276284</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-08T23:28:51Z</dc:date>
    </item>
  </channel>
</rss>

