<?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 Dates and IF statements in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Dates-and-IF-statements/m-p/7410#M86</link>
    <description>I'm working with a list of dates from a 20-year period.  The dates were in SAS format (from 1/1/60) and I've formatted them with the MONTHw. format.  &lt;BR /&gt;
&lt;BR /&gt;
I'm trying to use IF statements based upon the new MONTH values in my table, since I need to do the same thing based upon the month of the date and not the specific date itself (of which I have about 100,000 observations).  &lt;BR /&gt;
&lt;BR /&gt;
I've tried several things like:&lt;BR /&gt;
&lt;BR /&gt;
IF date='3', then x=y, etc., but SAS won't read my IF statement based on my MONTH values I created.  How do I get SAS to do this, as going back through the individual dates would be extremely time consuming task.  &lt;BR /&gt;
&lt;BR /&gt;
Thanks for any help you can give.</description>
    <pubDate>Tue, 11 Mar 2008 19:24:49 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-03-11T19:24:49Z</dc:date>
    <item>
      <title>Dates and IF statements</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Dates-and-IF-statements/m-p/7410#M86</link>
      <description>I'm working with a list of dates from a 20-year period.  The dates were in SAS format (from 1/1/60) and I've formatted them with the MONTHw. format.  &lt;BR /&gt;
&lt;BR /&gt;
I'm trying to use IF statements based upon the new MONTH values in my table, since I need to do the same thing based upon the month of the date and not the specific date itself (of which I have about 100,000 observations).  &lt;BR /&gt;
&lt;BR /&gt;
I've tried several things like:&lt;BR /&gt;
&lt;BR /&gt;
IF date='3', then x=y, etc., but SAS won't read my IF statement based on my MONTH values I created.  How do I get SAS to do this, as going back through the individual dates would be extremely time consuming task.  &lt;BR /&gt;
&lt;BR /&gt;
Thanks for any help you can give.</description>
      <pubDate>Tue, 11 Mar 2008 19:24:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Dates-and-IF-statements/m-p/7410#M86</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-03-11T19:24:49Z</dc:date>
    </item>
    <item>
      <title>Re: Dates and IF statements</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Dates-and-IF-statements/m-p/7411#M87</link>
      <description>two alternatives[pre]&lt;BR /&gt;
 if month( your_date_variable ) = 3 then do;&lt;BR /&gt;
    * do March processing ;&lt;BR /&gt;
 end;&lt;BR /&gt;
       &lt;BR /&gt;
 If your_date_variable  GT '31Dec2004'd  then do;&lt;BR /&gt;
    * process cases after 2004 ;&lt;BR /&gt;
 end;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Does that help?&lt;BR /&gt;
&lt;BR /&gt;
Even after you format a SAS date variable it is still a number of days since 1960. That is why SAS supports the date constants like '31Dec2004'd. &lt;BR /&gt;
The MONTH() function is a convenient way of extracting just that information from a SAS date variable.&lt;BR /&gt;
&lt;BR /&gt;
 &lt;BR /&gt;
&lt;BR /&gt;
PeterC</description>
      <pubDate>Tue, 11 Mar 2008 19:37:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Dates-and-IF-statements/m-p/7411#M87</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2008-03-11T19:37:22Z</dc:date>
    </item>
    <item>
      <title>Re: Dates and IF statements</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Dates-and-IF-statements/m-p/7412#M88</link>
      <description>&lt;P&gt;Hi:&lt;BR /&gt; The format only affects the DISPLAY of the date variable -- not the internal storage value of the date variable. So, for example, if I have a date variable called DATE that represents the date 11/15/1950, the INTERNAL, stored number for that date is -3334. DATE is a numeric variable. I can format DATE anyway I want for PROC PRINT or PROC FREQ. But, applying a MONTH format does not affect the internal storage of the number. And, it doesn't turn DATE into a character variable. &lt;BR /&gt; &lt;BR /&gt; So, if I needed to use DATE in an IF statement, these are all acceptable IF statements:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if date = -3334 then x=y;
if date = '15NOV1950'd then x=y;
if month(date) = 11 then x=y;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;This last IF statement uses &lt;A href="http://go.documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n0bn6385z4pweqn1qrpmklqtln99.htm&amp;amp;locale=en" target="_self"&gt;the MONTH function&lt;/A&gt; with the DATE variable to return a number from 1 to 12 -- which represents only the MONTH portion of my DATE variable value of -3334.&lt;BR /&gt; &lt;BR /&gt; cynthia&lt;BR /&gt; &lt;BR /&gt; To check out different DATE internal numbers and how a format only DISPLAYs a readable date, test this code by putting your date of interest between the single quotes where I have 15NOV1950 -- note that you absolutely need the quotes and the d -- to tell SAS that you're creating your numeric variable from a DATE constant:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mydate;
mydate = '15NOV1950'd;
date = mydate;
run;

ods listing;
proc print data=mydate;
title 'what is the internal number for a date';
format DATE mmmddyy10.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Jul 2017 12:21:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Dates-and-IF-statements/m-p/7412#M88</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2017-07-24T12:21:14Z</dc:date>
    </item>
  </channel>
</rss>

