<?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 Creatine a new column if Values in one column are less than value in another column in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Creatine-a-new-column-if-Values-in-one-column-are-less-than/m-p/796714#M33008</link>
    <description>&lt;P&gt;I have a data set currently i am working on..&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have found this community very helpful in solving my problems. Hnece, I am posting another question.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have various columns in this data set. One of the columns is HospitalDay and the other Is MethadoneStartDate.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both these columns have numbers in them ranging from -10 to 100..&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My question si I want to create a&amp;nbsp; new column called Methadone. The new column should have a 1 IF the value in Methadonestart date &amp;lt;HospitalDay. However,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having a hard time creating an If then statement for this . I think the issue is the hospitalday column has every row filled with a digit, but the methadone start date has a bunch of empty rows with Dots (.) as not everyone got methadone .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can i solve this?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 16 Feb 2022 21:27:22 GMT</pubDate>
    <dc:creator>manthan</dc:creator>
    <dc:date>2022-02-16T21:27:22Z</dc:date>
    <item>
      <title>Creatine a new column if Values in one column are less than value in another column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creatine-a-new-column-if-Values-in-one-column-are-less-than/m-p/796714#M33008</link>
      <description>&lt;P&gt;I have a data set currently i am working on..&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have found this community very helpful in solving my problems. Hnece, I am posting another question.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have various columns in this data set. One of the columns is HospitalDay and the other Is MethadoneStartDate.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both these columns have numbers in them ranging from -10 to 100..&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My question si I want to create a&amp;nbsp; new column called Methadone. The new column should have a 1 IF the value in Methadonestart date &amp;lt;HospitalDay. However,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having a hard time creating an If then statement for this . I think the issue is the hospitalday column has every row filled with a digit, but the methadone start date has a bunch of empty rows with Dots (.) as not everyone got methadone .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can i solve this?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Feb 2022 21:27:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creatine-a-new-column-if-Values-in-one-column-are-less-than/m-p/796714#M33008</guid>
      <dc:creator>manthan</dc:creator>
      <dc:date>2022-02-16T21:27:22Z</dc:date>
    </item>
    <item>
      <title>Re: Creatine a new column if Values in one column are less than value in another column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creatine-a-new-column-if-Values-in-one-column-are-less-than/m-p/796718#M33010</link>
      <description>&lt;P&gt;A dot(.) in numeric variable in SAS means "missing value", e.g.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  a = 17;
  b = 42;
  c = .;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;this will create a data set Test with 3 variables, a, b, and c, but c will have missing value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In SAS, in comparison expressions a missing value is considered to be "less than any number", so in the IF expressions like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  if c&amp;lt;a then ...
  if c&amp;lt;b then ..&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;both will be evaluated as true.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you have data like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input HospitalDay MethadoneStartDate;
cards;
20 50
50 20
20 .
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the last observation in the code like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  if MethadoneStartDate &amp;lt; HospitalDay then Methadone = 1;
                                      else Methadone = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will be evaluated to true and Methadone will be set to 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to add some additional test&amp;nbsp;MethadoneStartDate to be not missing, e.g.;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  if . &amp;lt; MethadoneStartDate &amp;lt; HospitalDay then Methadone = 1;
                                          else Methadone = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In this case condition says:&amp;nbsp;MethadoneStartDate must be greater than missing value (which means to be non missing) and smaller than&amp;nbsp;HospitalDay.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope it helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Feb 2022 21:52:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creatine-a-new-column-if-Values-in-one-column-are-less-than/m-p/796718#M33010</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-02-16T21:52:40Z</dc:date>
    </item>
  </channel>
</rss>

