<?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: SAS Dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Dates/m-p/731628#M227907</link>
    <description>&lt;P&gt;Thanks for replying! Every time I run the code I would like it to run for the prior month.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 06 Apr 2021 16:00:54 GMT</pubDate>
    <dc:creator>wisej</dc:creator>
    <dc:date>2021-04-06T16:00:54Z</dc:date>
    <item>
      <title>SAS Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Dates/m-p/731615#M227903</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a date variable formatted as yyddmm (ex. 2021-04-06). I need to run descriptive statistics on data collected last month. Any advice on how to do this if the date variable is formatted this way? I appreciate any help!&lt;/P&gt;</description>
      <pubDate>Tue, 06 Apr 2021 14:56:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Dates/m-p/731615#M227903</guid>
      <dc:creator>wisej</dc:creator>
      <dc:date>2021-04-06T14:56:17Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Dates/m-p/731617#M227904</link>
      <description>&lt;P&gt;By last month do you mean March 2021 or do you mean whenever you run the code it should run for the prior month?&lt;/P&gt;
&lt;P&gt;Assuming your variable is called dateVariable and is a SAS date, ie numeric with a date format you can filter your data with a WHERE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where intnx('month', dateVariable, 0, 'b') = '01Mar2021'd;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or dynamically:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where intnx('month', today(), -1, 'b') = intnx('month', dateVariable, 0, 'b');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/361594"&gt;@wisej&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a date variable formatted as yyddmm (ex. 2021-04-06). I need to run descriptive statistics on data collected last month. Any advice on how to do this if the date variable is formatted this way? I appreciate any help!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Apr 2021 15:01:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Dates/m-p/731617#M227904</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-06T15:01:05Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Dates/m-p/731618#M227905</link>
      <description>And a yyddmm is very, very rare, it's almost always yymmdd so I would confirm that. &lt;BR /&gt;SAS doesn't have a format for that date format AFAIK .....</description>
      <pubDate>Tue, 06 Apr 2021 15:03:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Dates/m-p/731618#M227905</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-06T15:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Dates/m-p/731619#M227906</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/361594"&gt;@wisej&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a date variable formatted as yyddmm (ex. 2021-04-06). I need to run descriptive statistics on data collected last month. Any advice on how to do this if the date variable is formatted this way? I appreciate any help!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Assign a format to the date variable, for example yymm. and then PROC MEANS and almost all other PROCs that do descriptive statistics will provide you with the statistics for each month in the data set.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Apr 2021 15:16:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Dates/m-p/731619#M227906</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-06T15:16:05Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Dates/m-p/731628#M227907</link>
      <description>&lt;P&gt;Thanks for replying! Every time I run the code I would like it to run for the prior month.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Apr 2021 16:00:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Dates/m-p/731628#M227907</guid>
      <dc:creator>wisej</dc:creator>
      <dc:date>2021-04-06T16:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Dates/m-p/731630#M227908</link>
      <description>&lt;P&gt;Can you please explain the syntax of the where statement you provided? Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 06 Apr 2021 16:06:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Dates/m-p/731630#M227908</guid>
      <dc:creator>wisej</dc:creator>
      <dc:date>2021-04-06T16:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Dates/m-p/731649#M227917</link>
      <description>&lt;P&gt;INTNX increments dates, the first parameter specifies the interval, month. The second is the date variable and the third is the increment, 0 is same month, -1 is prior month, 1 is next month. &lt;BR /&gt;The last, says to align it to the beginning of the month. TODAY() returns the current date so it would convert that date to the start of the prior month and check if that matches the date variable which has been aligned to the beginning of the month.&lt;BR /&gt;&lt;BR /&gt;An alternative would be to compare the year and month components but that's more work IMO.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p10v3sa3i4kfxfn1sovhi5xzxh8n.htm&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p10v3sa3i4kfxfn1sovhi5xzxh8n.htm&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Apr 2021 16:59:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Dates/m-p/731649#M227917</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-06T16:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Dates/m-p/731747#M227967</link>
      <description>&lt;P&gt;Please have a look at the sample code and data. This run proc univariate on previous months data; Hope this will solve your problem.&lt;BR /&gt;I have taken aa sample data to show that it works.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
informat date1 yymmdd10.;
format date1  yymmdd10.;
input date1 somevar;
datalines;
2021-02-06 15
2021-02-06 11
2021-03-01 09
2021-03-10 12
2021-03-16 14
2021-03-19 16
2021-03-25 08
2021-03-29 03
2021-04-06 12
2021-04-06 21
;
run;

%let last_month = %sysfunc(month(%sysfunc(intnx(month,%sysfunc(date()),-1))));

proc univariate data=test(where=(month(date1)=&amp;amp;last_month.));
var somevar;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Apr 2021 23:16:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Dates/m-p/731747#M227967</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-04-06T23:16:00Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Dates/m-p/731787#M227983</link>
      <description>What if the years are different? What if they have 2020 data in the data set as well?</description>
      <pubDate>Wed, 07 Apr 2021 02:37:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Dates/m-p/731787#M227983</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-07T02:37:07Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Dates/m-p/731801#M227988</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/361594"&gt;@wisej&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a date variable formatted as yyddmm (ex. 2021-04-06). I need to run descriptive statistics on data collected last month. Any advice on how to do this if the date variable is formatted this way? I appreciate any help!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The word FORMAT has a special meaning in SAS. A format is instructions for how to display values as text.&amp;nbsp; SAS does not have any date format that would display dates in YDM order.&amp;nbsp; It does have some, like YYMMDD, that will display dates in YMD order.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For purposes of providing an answer lets assume that there is a variable named DATE that contains date values (number of days since 1960).&amp;nbsp; Most likely if it display as string like '2021-04-06' then it has the format specification YYMMDD10. attached to it (although there are other date specifications that would display dates in that same style).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To test for last month you need to know today's month.&amp;nbsp; You can use the DATE() function (or its alias name of TODAY()) to get today's date.&amp;nbsp; Then you can move back one month to find last month by using the INTNX() function with the interval type of month and and offset of negative one.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;intnx('month',today(),-1)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;then you can test if the value is in last month in a number of ways.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could convert DATE to the same date and compare:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where intnx('month',DATE,-1) = intnx('month',today(),-1) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could convert both the strings using a format that only displays the YEAR and MONTH part of the date and compare those strings.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where put(DATE,monyy7.) = put(intnx('month',today(),-1),monyy7.) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could test if the date is in the interval defined by the first and last day of the month.&amp;nbsp; That might work faster if the source data is indexed on DATE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where date between intnx('month',today(),-1,'b') and intnx('month',today(),-1,'e');&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Apr 2021 04:40:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Dates/m-p/731801#M227988</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-07T04:40:49Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Dates/m-p/731997#M228085</link>
      <description>&lt;P&gt;The dataset does contain data from 2019 and 2020 as well.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Apr 2021 17:46:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Dates/m-p/731997#M228085</guid>
      <dc:creator>wisej</dc:creator>
      <dc:date>2021-04-07T17:46:30Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Dates/m-p/732868#M228373</link>
      <description>&lt;P&gt;This takes care of both month and year;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
informat date1 yymmdd10.;
format date1  yymmdd10.;
input date1 somevar;
datalines;
2020-03-01 09
2020-03-10 12
2020-03-16 14
2020-03-19 16
2020-03-25 08
2021-02-06 15
2021-02-06 11
2021-03-01 09
2021-03-10 12
2021-03-16 14
2021-03-19 16
2021-03-25 08
2021-03-29 03
2021-04-06 12
2021-04-06 21
;
run;

proc univariate data=test(where=(put(date1,monyy7.)="%sysfunc(intnx(month,%sysfunc(date()),-1),monyy7.)"));
var somevar;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV id="IDX" class="proc_title_group"&gt;
&lt;P class="c proctitle"&gt;From the result&amp;nbsp; we see that there were&amp;nbsp; six observations in the analysis.&lt;BR /&gt;The original dataset too has six observations for last month (Mar2021)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;/DIV&gt;
&lt;SECTION&gt;
&lt;ARTICLE aria-label="Moments"&gt;
&lt;TABLE class="table" aria-label="Moments"&gt;&lt;CAPTION aria-label="Moments"&gt;&amp;nbsp;&lt;/CAPTION&gt;&lt;COLGROUP&gt;&lt;COL /&gt;&lt;COL /&gt;&lt;COL /&gt;&lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="c b header" colspan="4" scope="colgroup"&gt;Moments&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="rowheader" scope="row"&gt;N&lt;/TH&gt;
&lt;TD class="r data"&gt;6&lt;/TD&gt;
&lt;TH class="rowheader" scope="row"&gt;Sum Weights&lt;/TH&gt;
&lt;TD class="r data"&gt;6&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="rowheader" scope="row"&gt;Mean&lt;/TH&gt;
&lt;TD class="r data"&gt;10.3333333&lt;/TD&gt;
&lt;TH class="rowheader" scope="row"&gt;Sum Observations&lt;/TH&gt;
&lt;TD class="r data"&gt;62&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="rowheader" scope="row"&gt;Std Deviation&lt;/TH&gt;
&lt;TD class="r data"&gt;4.67618078&lt;/TD&gt;
&lt;TH class="rowheader" scope="row"&gt;Variance&lt;/TH&gt;
&lt;TD class="r data"&gt;21.8666667&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="rowheader" scope="row"&gt;Skewness&lt;/TH&gt;
&lt;TD class="r data"&gt;-0.5091971&lt;/TD&gt;
&lt;TH class="rowheader" scope="row"&gt;Kurtosis&lt;/TH&gt;
&lt;TD class="r data"&gt;-0.182648&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="rowheader" scope="row"&gt;Uncorrected SS&lt;/TH&gt;
&lt;TD class="r data"&gt;750&lt;/TD&gt;
&lt;TH class="rowheader" scope="row"&gt;Corrected SS&lt;/TH&gt;
&lt;TD class="r data"&gt;109.333333&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="rowheader" scope="row"&gt;Coeff Variation&lt;/TH&gt;
&lt;TD class="r data"&gt;45.2533624&lt;/TD&gt;
&lt;TH class="rowheader" scope="row"&gt;Std Error Mean&lt;/TH&gt;
&lt;TD class="r data"&gt;1.90904281&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/ARTICLE&gt;
&lt;/SECTION&gt;</description>
      <pubDate>Sun, 11 Apr 2021 15:38:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Dates/m-p/732868#M228373</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-04-11T15:38:14Z</dc:date>
    </item>
  </channel>
</rss>

