<?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: assign value to new column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/assign-value-to-new-column/m-p/941431#M369341</link>
    <description>&lt;P&gt;SAS very nicely provides the ability to have multiple comparisons such as&amp;nbsp;&amp;nbsp; a &amp;lt; b &amp;lt; c as a simple construct.&lt;/P&gt;
&lt;P&gt;So if you want to exclude the missing values for First_afib from returning true with code like&amp;nbsp;First_AFIB&amp;lt;First_Ischemic then provide a lower bound for First_afib:&lt;/P&gt;
&lt;PRE&gt;if 0&amp;lt; First_AFIB&amp;lt;First_Ischemic then ...&lt;/PRE&gt;
&lt;P&gt;Since your values are mostly dates you could use a date literal that you expect never to appear in the data a valid such as&lt;/P&gt;
&lt;PRE&gt;if '01JAN1800'd &amp;lt; First_AFIB&amp;lt;First_Ischemic then ...&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 28 Aug 2024 14:08:23 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2024-08-28T14:08:23Z</dc:date>
    <item>
      <title>assign value to new column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assign-value-to-new-column/m-p/941420#M369338</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I create a new column for preafib and prepfo BUT ignore the missing row when assigning a value to the new variable.&lt;/P&gt;&lt;P&gt;without assigning a value to the new variable when both&amp;nbsp; &lt;SPAN&gt;First_Ischemic or&amp;nbsp; First_Hemorrhagic is blank&lt;/SPAN&gt;. For example, ID =&amp;nbsp;&lt;SPAN&gt;032462&lt;/SPAN&gt; my code was able to calculate when afib is less then &lt;SPAN&gt;First_Ischemic or First_Hemorrhagic&lt;/SPAN&gt;&amp;nbsp;but it is also assigning a value for when both columns are missing. I do not want it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, ID=&lt;SPAN&gt;023434 is assigning a value of YES to preafib because&amp;nbsp;&amp;nbsp;First_Ischemic = .&amp;nbsp; so it recognizes&amp;nbsp;First_Ischemic to be less than First_AFIB=21JUN2003. How can I rewrite my code to ignore the missing and only calculate for the non-missing rows. Thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data a;
input ID $6. First_Ischemic First_Hemorrhagic first_AFIB first_PFO ;
format First_Ischemic First_Hemorrhagic first_AFIB first_PFO date9.;
informat First_Ischemic First_Hemorrhagic first_AFIB first_PFO date9.;
datalines;
011386   23SEP2004  10FEB2020  .   . 
034627   01DEC2009  30NOV2009  .   10FEB2020     
011427   10JUL2003   .   .   .
012666   .   18SEP2006   20JUN2002   .
023434   .   18OCT2002   21JUN2003   . 
020485   15JUL2009   .   .   .   
032462   .   .   .    20JUN2002  
011386   23SEP2004  10FEB2020  .   . 
;
run;
proc sort data=a; by id; run;
data Prepost;
set a;
by id;
if First_AFIB ne .  then do;
if First_AFIB&amp;lt;First_Ischemic or First_Hemorrhagic then Preafib='Yes';
else if First_AFIB&amp;gt; First_Ischemic or First_Hemorrhagic then Preafib='No';
end;
if first_PFO ne .  then do;
if first_PFO&amp;lt;First_Ischemic or First_Hemorrhagic then Prepfo='Yes';
if first_PFO&amp;gt; First_Ischemic or First_Hemorrhagic then Prepfo='No';
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Output of interest&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Obs&lt;/TD&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;First_Ischemic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/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;020485&lt;/TD&gt;&lt;TD&gt;15JUL2009&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;023434&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;18OCT2002&lt;/TD&gt;&lt;TD&gt;21JUN2003&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;No&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;032462&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;20JUN2002&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;034627&lt;/TD&gt;&lt;TD&gt;01DEC2009&lt;/TD&gt;&lt;TD&gt;30NOV2009&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;10FEB2020&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;No&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 13:40:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assign-value-to-new-column/m-p/941420#M369338</guid>
      <dc:creator>CathyVI</dc:creator>
      <dc:date>2024-08-28T13:40:07Z</dc:date>
    </item>
    <item>
      <title>Re: assign value to new column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assign-value-to-new-column/m-p/941428#M369339</link>
      <description>&lt;P&gt;You have to test to see if first_ischemic and first_hemmorrhagic are both missing. You haven't done that, so in your code this isn't accounted for. I think this is what you want&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if first_PFO ne .  then do;
    if first_PFO&amp;lt;First_Ischemic or first_PFO&amp;lt;First_Hemorrhagic then Prepfo='Yes';
    if (not missing(first_ischemic) or not missing(first_Hemorrhagic)) and 
        (first_PFO&amp;gt; First_Ischemic or first_PFO&amp;gt;First_Hemorrhagic) then Prepfo='No';
end;&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;Also your constructed IF statement&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if first_PFO&amp;lt;&lt;FONT color="#FF0000"&gt;First_Ischemic or First_Hemorrhagic&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;seems wrong to me and I have adjusted this in my code.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 14:20:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assign-value-to-new-column/m-p/941428#M369339</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-08-28T14:20:44Z</dc:date>
    </item>
    <item>
      <title>Re: assign value to new column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assign-value-to-new-column/m-p/941431#M369341</link>
      <description>&lt;P&gt;SAS very nicely provides the ability to have multiple comparisons such as&amp;nbsp;&amp;nbsp; a &amp;lt; b &amp;lt; c as a simple construct.&lt;/P&gt;
&lt;P&gt;So if you want to exclude the missing values for First_afib from returning true with code like&amp;nbsp;First_AFIB&amp;lt;First_Ischemic then provide a lower bound for First_afib:&lt;/P&gt;
&lt;PRE&gt;if 0&amp;lt; First_AFIB&amp;lt;First_Ischemic then ...&lt;/PRE&gt;
&lt;P&gt;Since your values are mostly dates you could use a date literal that you expect never to appear in the data a valid such as&lt;/P&gt;
&lt;PRE&gt;if '01JAN1800'd &amp;lt; First_AFIB&amp;lt;First_Ischemic then ...&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 14:08:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assign-value-to-new-column/m-p/941431#M369341</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-08-28T14:08:23Z</dc:date>
    </item>
    <item>
      <title>Re: assign value to new column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assign-value-to-new-column/m-p/941445#M369343</link>
      <description>&lt;P&gt;What test do you think this code is performing?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;First_AFIB&amp;lt;First_Ischemic or First_Hemorrhagic&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;SAS will treat that as this test:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(First_AFIB&amp;lt;First_Ischemic) or (First_Hemorrhagic)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So if FIRST_HEMORRHAGIC is not missing and not zero (zero is the date '01JAN1960'd) then that test will be TRUE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 14:32:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assign-value-to-new-column/m-p/941445#M369343</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-08-28T14:32:22Z</dc:date>
    </item>
    <item>
      <title>Re: assign value to new column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assign-value-to-new-column/m-p/941448#M369345</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What do you think is wrong here. I expected ID=&lt;SPAN&gt;012666 to be "Yes"&amp;nbsp; if First_AFIB&amp;lt;First_Ischemic or First_AFIB&amp;lt;First_Hemorrhagic but am getting a "NO". I have modified the code few times but not the right output.&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data Prepost1;
set a;
by id;
if First_AFIB ne .  then do;
if First_AFIB&amp;lt;First_Ischemic or First_AFIB&amp;lt;First_Hemorrhagic then Preafib='Yes';
if (not missing(first_ischemic) or not missing(first_Hemorrhagic)) and
     (First_AFIB&amp;gt; First_Ischemic or First_AFIB&amp;gt;First_Hemorrhagic) then Preafib='No';
end;
if first_PFO ne .  then do;
    if first_PFO&amp;lt;First_Ischemic or first_PFO&amp;lt;First_Hemorrhagic then Prepfo='Yes';
    if (not missing(first_ischemic) or not missing(first_Hemorrhagic)) and 
        (first_PFO&amp;gt; First_Ischemic or first_PFO&amp;lt;First_Hemorrhagic) then Prepfo='No';      
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 14:41:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assign-value-to-new-column/m-p/941448#M369345</guid>
      <dc:creator>CathyVI</dc:creator>
      <dc:date>2024-08-28T14:41:54Z</dc:date>
    </item>
    <item>
      <title>Re: assign value to new column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assign-value-to-new-column/m-p/941452#M369346</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if First_AFIB ne .  then do;
     if First_AFIB&amp;lt;First_Ischemic or First_AFIB&amp;lt;First_Hemorrhagic then Preafib='Yes';
     else if (not missing(first_ischemic) or not missing(first_Hemorrhagic)) and
          (First_AFIB&amp;gt; First_Ischemic or First_AFIB&amp;gt;First_Hemorrhagic) then Preafib='No';
end;
if first_PFO ne .  then do;
    if first_PFO&amp;lt;First_Ischemic or first_PFO&amp;lt;First_Hemorrhagic then Prepfo='Yes';
    else if (not missing(first_ischemic) or not missing(first_Hemorrhagic)) and 
        (first_PFO&amp;gt; First_Ischemic or first_PFO&amp;lt;First_Hemorrhagic) then Prepfo='No';      
end;&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;You will find it extremely helpful if you work out the logic in your head and/or on a piece of paper, so all possible situations are accounted for, and then program from that.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 14:49:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assign-value-to-new-column/m-p/941452#M369346</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-08-28T14:49:10Z</dc:date>
    </item>
  </channel>
</rss>

