<?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: creating new categorical variable using Date variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/creating-new-categorical-variable-using-Date-variables/m-p/250190#M56575</link>
    <description>&lt;P&gt;Hi Satish,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically, the new categorical variable could be defined as follows (in a data step; similarly in PROC SQL):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;labs_at_ER=(Room_Start_Date&amp;lt;=collection_date&amp;lt;=Room_End_Date);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(Assumption: Your datetime variables are &lt;EM&gt;SAS&lt;/EM&gt; &lt;EM&gt;datetime&lt;/EM&gt; values or at least in a format that preserves chronological order.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As created above, labs_at_ER would be a numeric variable, to which you could assign a numeric format that maps 1 to "yes" and 0&amp;nbsp;to "no." This has several advantages over a character variable with values "yes" and "no."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's up to you to decide if "&amp;lt;=" or "&amp;lt;" is&amp;nbsp;more appropriate in either place in the definition. You should also add code (e.g. an IF condition) to&amp;nbsp;handle missing values of the three variables involved in the inequality.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Correction: The numeric format should, of course, map &lt;STRONG&gt;0&lt;/STRONG&gt; to "no", not 2.&lt;/P&gt;</description>
    <pubDate>Mon, 15 Feb 2016 21:52:10 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2016-02-15T21:52:10Z</dc:date>
    <item>
      <title>creating new categorical variable using Date variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-new-categorical-variable-using-Date-variables/m-p/250182#M56574</link>
      <description>&lt;P&gt;Hi group,&lt;/P&gt;
&lt;P&gt;I have a data with Emergency Room visits with Room start date (datetime) and Room end dates. I also have labs for the patients captured as collection_date (datetime). I have to identify labs which were taken at ER using Room_Start_Date&amp;nbsp;(datetime) and Room_End_Date (datetime). If labs were taken between Room_Start_Date and Room_End_Date, then they are considered labs_at_ER, which need to create a new categorical variable (yes/no). Can anyone please help me with the SAS codes to create this new variable? Note: all my date variables are in datetime format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot,&lt;/P&gt;
&lt;P&gt;Satish&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2016 20:32:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-new-categorical-variable-using-Date-variables/m-p/250182#M56574</guid>
      <dc:creator>smunigala</dc:creator>
      <dc:date>2016-02-15T20:32:06Z</dc:date>
    </item>
    <item>
      <title>Re: creating new categorical variable using Date variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-new-categorical-variable-using-Date-variables/m-p/250190#M56575</link>
      <description>&lt;P&gt;Hi Satish,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically, the new categorical variable could be defined as follows (in a data step; similarly in PROC SQL):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;labs_at_ER=(Room_Start_Date&amp;lt;=collection_date&amp;lt;=Room_End_Date);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(Assumption: Your datetime variables are &lt;EM&gt;SAS&lt;/EM&gt; &lt;EM&gt;datetime&lt;/EM&gt; values or at least in a format that preserves chronological order.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As created above, labs_at_ER would be a numeric variable, to which you could assign a numeric format that maps 1 to "yes" and 0&amp;nbsp;to "no." This has several advantages over a character variable with values "yes" and "no."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's up to you to decide if "&amp;lt;=" or "&amp;lt;" is&amp;nbsp;more appropriate in either place in the definition. You should also add code (e.g. an IF condition) to&amp;nbsp;handle missing values of the three variables involved in the inequality.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Correction: The numeric format should, of course, map &lt;STRONG&gt;0&lt;/STRONG&gt; to "no", not 2.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2016 21:52:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-new-categorical-variable-using-Date-variables/m-p/250190#M56575</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-02-15T21:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: creating new categorical variable using Date variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-new-categorical-variable-using-Date-variables/m-p/250662#M56609</link>
      <description>One handy feature that would support this kind of connection is the USER FORMAT&lt;BR /&gt;This can supply a value where nunbers fall within ranges.&lt;BR /&gt;See PROC FORMAT</description>
      <pubDate>Wed, 17 Feb 2016 17:57:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-new-categorical-variable-using-Date-variables/m-p/250662#M56609</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2016-02-17T17:57:40Z</dc:date>
    </item>
  </channel>
</rss>

