<?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: Using IF-ELSE-IF statement to create new date variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-ELSE-IF-statement-to-create-new-date-variable/m-p/376033#M276561</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/151070"&gt;@yiyizhao86&lt;/a&gt; wrote:&lt;BR /&gt;Thank you so much for you reply! But the date format in the original dataset is YYMMDD10.&lt;BR /&gt;Do I need to reformat the date in the original file first?&lt;BR /&gt;&lt;BR /&gt;I changed into the '01Jan2014'd in the if-else statement but still I got weird outputs&lt;BR /&gt;&lt;BR /&gt;Thanks again!&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Format has NOTHING to do with arithmetic. Formats are for display or grouping.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show the code and the results that are "weird" and the expected results.&lt;/P&gt;</description>
    <pubDate>Fri, 14 Jul 2017 14:53:19 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-07-14T14:53:19Z</dc:date>
    <item>
      <title>Using IF-ELSE-IF statement to create new date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-ELSE-IF-statement-to-create-new-date-variable/m-p/376005#M276558</link>
      <description>&lt;P&gt;Hi! I have an original dataset as the following:&lt;/P&gt;&lt;P&gt;id &amp;nbsp; &amp;nbsp; &amp;nbsp;start_date &amp;nbsp; &amp;nbsp; &amp;nbsp; end_date&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;2016-06-01 &amp;nbsp; &amp;nbsp; 2016-07-01&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;2013-02-01 &amp;nbsp; &amp;nbsp; 2014-04-06&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;2015-01-03 &amp;nbsp; &amp;nbsp; 2016-03-07&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp;2013-01-01 &amp;nbsp; &amp;nbsp; 2015-03-06&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For each row, I would like to compute the days between the start date and the end date that is between year 2014-01-01 to 2014-12-31.&lt;/P&gt;&lt;P&gt;I was thinking that I can create two new variables per row so that:&lt;/P&gt;&lt;P&gt;id &amp;nbsp; &amp;nbsp; &amp;nbsp;start_date &amp;nbsp; &amp;nbsp; &amp;nbsp; end_date &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;date1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;date2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;2016-06-01 &amp;nbsp; &amp;nbsp; 2016-07-01 &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;2013-02-01 &amp;nbsp; &amp;nbsp; 2014-04-06 &amp;nbsp; &amp;nbsp; 2014-01-01 &amp;nbsp; &amp;nbsp;2014-04-06&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;2015-01-03 &amp;nbsp; &amp;nbsp; 2016-03-07 &amp;nbsp; &amp;nbsp; . &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp;2013-01-01 &amp;nbsp; &amp;nbsp; 2015-03-06 &amp;nbsp; &amp;nbsp; 2014-01-01 &amp;nbsp; &amp;nbsp; 2014-12-31&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and then I can drop the rows with missing value and compute the difference between date2 and date1. But the following code does not work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; set original;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; format date1 date2 YYMMDD10.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if start_date &amp;lt;= 2004-01-01 then date1 = 2004-01-01;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else if start_date &amp;lt;= 2004-12-31 then date1 = start_date;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else date1 = .;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if end_date &amp;lt; 2004-01-01 then date2 =.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else if end_date &amp;lt;= 2004-12-31 then date2 = end_date;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else date2 = 2004-12-31;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please help me fixing the above code or give me some suggesting about how to acheive my goal? Thank you so much! I really appreciate it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yiyi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 14:01:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IF-ELSE-IF-statement-to-create-new-date-variable/m-p/376005#M276558</guid>
      <dc:creator>yiyizhao86</dc:creator>
      <dc:date>2017-07-14T14:01:05Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF-ELSE-IF statement to create new date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-ELSE-IF-statement-to-create-new-date-variable/m-p/376007#M276559</link>
      <description>&lt;P&gt;Once you think about your formulas, you'll realize that 2014-01-01 = 2014 - 1 - 1 = 2012.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To refer to a specific day, use a different form: &amp;nbsp;'01Jan2014'd&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do not put a space between the closing quote and the letter d&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And be careful about using 2004 vs. using 2014&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 14:11:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IF-ELSE-IF-statement-to-create-new-date-variable/m-p/376007#M276559</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-14T14:11:19Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF-ELSE-IF statement to create new date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-ELSE-IF-statement-to-create-new-date-variable/m-p/376014#M276560</link>
      <description>Thank you so much for you reply! But the date format in the original dataset is YYMMDD10.&lt;BR /&gt;Do I need to reformat the date in the original file first?&lt;BR /&gt;&lt;BR /&gt;I changed into the '01Jan2014'd in the if-else statement but still I got weird outputs&lt;BR /&gt;&lt;BR /&gt;Thanks again!</description>
      <pubDate>Fri, 14 Jul 2017 14:22:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IF-ELSE-IF-statement-to-create-new-date-variable/m-p/376014#M276560</guid>
      <dc:creator>yiyizhao86</dc:creator>
      <dc:date>2017-07-14T14:22:58Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF-ELSE-IF statement to create new date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-ELSE-IF-statement-to-create-new-date-variable/m-p/376033#M276561</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/151070"&gt;@yiyizhao86&lt;/a&gt; wrote:&lt;BR /&gt;Thank you so much for you reply! But the date format in the original dataset is YYMMDD10.&lt;BR /&gt;Do I need to reformat the date in the original file first?&lt;BR /&gt;&lt;BR /&gt;I changed into the '01Jan2014'd in the if-else statement but still I got weird outputs&lt;BR /&gt;&lt;BR /&gt;Thanks again!&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Format has NOTHING to do with arithmetic. Formats are for display or grouping.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show the code and the results that are "weird" and the expected results.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 14:53:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IF-ELSE-IF-statement-to-create-new-date-variable/m-p/376033#M276561</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-07-14T14:53:19Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF-ELSE-IF statement to create new date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-ELSE-IF-statement-to-create-new-date-variable/m-p/376076#M276562</link>
      <description>&lt;P&gt;Weird results can be debugged. &amp;nbsp;Show what you did, and what the result was. &amp;nbsp;So far, you are moving in right direction and reformatting is not necessary.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 15:47:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IF-ELSE-IF-statement-to-create-new-date-variable/m-p/376076#M276562</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-14T15:47:32Z</dc:date>
    </item>
  </channel>
</rss>

