<?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: Keep date9. format during if else statement in SAS in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Keep-date9-format-during-if-else-statement-in-SAS/m-p/794633#M81534</link>
    <description>What does ' my 'format new_date date9.' step doesn't work' mean?&lt;BR /&gt;&lt;BR /&gt;Post the log. &lt;BR /&gt;&lt;BR /&gt;Since you're using "" to check for missing, that would imply that your date variables are character not numeric and you cannot apply a numeric format to a character variable. In this case you need to also convert the dates to numerics variables. &lt;BR /&gt;&lt;BR /&gt;Is your first condition correct? It checks that both date1 and date2 are not missing and then assigns date1. Then the ELSE checks if DATE2 is missing and assigns Date1? Both essentially assign the Date1 value to DATE. &lt;BR /&gt;&lt;BR /&gt;Also, is this homework? If not use COALESCE/COALESCEC instead. &lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Fri, 04 Feb 2022 22:33:13 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2022-02-04T22:33:13Z</dc:date>
    <item>
      <title>Keep date9. format during if else statement in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Keep-date9-format-during-if-else-statement-in-SAS/m-p/794631#M81533</link>
      <description>&lt;P&gt;There has to be a simpler solution to this and I am not sure why I'm having so much difficulty. I have two date vars, with date9. format. I simply want to create a new date variable in the same data step based on these two variables, but can't without it converting to numeric (or character if I try and use 'put' statements but then my 'format new_date date9.' step doesn't work . help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data data1;&lt;BR /&gt;set data;&lt;BR /&gt;if date1^='' and date2^='' then new_date=date1;&lt;BR /&gt;else if date2='' then new_date=date1;&lt;BR /&gt;run;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Feb 2022 22:28:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Keep-date9-format-during-if-else-statement-in-SAS/m-p/794631#M81533</guid>
      <dc:creator>richart</dc:creator>
      <dc:date>2022-02-04T22:28:19Z</dc:date>
    </item>
    <item>
      <title>Re: Keep date9. format during if else statement in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Keep-date9-format-during-if-else-statement-in-SAS/m-p/794633#M81534</link>
      <description>What does ' my 'format new_date date9.' step doesn't work' mean?&lt;BR /&gt;&lt;BR /&gt;Post the log. &lt;BR /&gt;&lt;BR /&gt;Since you're using "" to check for missing, that would imply that your date variables are character not numeric and you cannot apply a numeric format to a character variable. In this case you need to also convert the dates to numerics variables. &lt;BR /&gt;&lt;BR /&gt;Is your first condition correct? It checks that both date1 and date2 are not missing and then assigns date1. Then the ELSE checks if DATE2 is missing and assigns Date1? Both essentially assign the Date1 value to DATE. &lt;BR /&gt;&lt;BR /&gt;Also, is this homework? If not use COALESCE/COALESCEC instead. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 04 Feb 2022 22:33:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Keep-date9-format-during-if-else-statement-in-SAS/m-p/794633#M81534</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-02-04T22:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: Keep date9. format during if else statement in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Keep-date9-format-during-if-else-statement-in-SAS/m-p/794634#M81535</link>
      <description>sorry and thanks... I think me forgetting to use . instead of '' for the date vars messed everything up. I now do this and it works:&lt;BR /&gt;&lt;BR /&gt;data data1;&lt;BR /&gt;set data;&lt;BR /&gt;if date1^=. and date2^=. then new_date=date1;&lt;BR /&gt;else if date2=. then new_date=date1;&lt;BR /&gt;format new_date date9.;&lt;BR /&gt;run;</description>
      <pubDate>Fri, 04 Feb 2022 22:41:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Keep-date9-format-during-if-else-statement-in-SAS/m-p/794634#M81535</guid>
      <dc:creator>richart</dc:creator>
      <dc:date>2022-02-04T22:41:29Z</dc:date>
    </item>
    <item>
      <title>Re: Keep date9. format during if else statement in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Keep-date9-format-during-if-else-statement-in-SAS/m-p/794635#M81536</link>
      <description>Glad it worked and hope that logic is correct.</description>
      <pubDate>Fri, 04 Feb 2022 22:47:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Keep-date9-format-during-if-else-statement-in-SAS/m-p/794635#M81536</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-02-04T22:47:55Z</dc:date>
    </item>
  </channel>
</rss>

