<?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: Select only first day of each month over multiple years in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-only-first-day-of-each-month-over-multiple-years/m-p/681376#M36933</link>
    <description>&lt;P&gt;You can't use a FUNCTION such as MONTH() in a BY statement. That is causing your error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Collapsed how?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It might help to show some example data and what you expect the output to look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I might start with a guess with something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc freq data=have noprint;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; where eventid&amp;gt;0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; tables evstdate / out=want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; format evstdate yymon. ;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Thu, 03 Sep 2020 15:14:53 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-09-03T15:14:53Z</dc:date>
    <item>
      <title>Select only first day of each month over multiple years</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-only-first-day-of-each-month-over-multiple-years/m-p/681177#M36924</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I need to select the first day of each month for multiple years. I have daily admissions for 10 years.&amp;nbsp; I need this collapsed into one row for the first date of each month over the ten years.&amp;nbsp; Ultimately, I need only 120 rows rather than 3650 rows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have summed daily admissions (to hospital) for each month of each year.&amp;nbsp; This gives me one column with the total admissions by month/year, but a row for each day of that month.&amp;nbsp; When I try proc sort with no dupkey by month(date) it fails at the nodupkey step.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Step 1 - works fine*/&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table WANT_1 as select *,&lt;BR /&gt;case when eventid&amp;gt;0 then count(eventid) else . end as monthly_admissions&lt;BR /&gt;from HAVE&lt;BR /&gt;group by month(evstdate);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Step 2 - does not work fine*/&lt;/P&gt;&lt;P&gt;proc sort data=WANT_1 out=WANT_2 nodupkey ; by month(admission_date); run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At step 2, I get this error message beneath "by month(admission_date)" :&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, ;, -, :, DECENDING, DESCENDING, DESENDING, _ALL_, _CHARACTER_,&lt;BR /&gt;_CHAR_, _NUMERIC_.&lt;/P&gt;&lt;P&gt;33 proc sort data=count_month out=count_month_a nodupkey ; by month(admission_date); run;&lt;BR /&gt;_&lt;BR /&gt;200&lt;BR /&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anybody help with this?&amp;nbsp; Many, many thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 23:14:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-only-first-day-of-each-month-over-multiple-years/m-p/681177#M36924</guid>
      <dc:creator>drshashlik</dc:creator>
      <dc:date>2020-09-02T23:14:17Z</dc:date>
    </item>
    <item>
      <title>Re: Select only first day of each month over multiple years</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-only-first-day-of-each-month-over-multiple-years/m-p/681180#M36926</link>
      <description>&lt;P&gt;Does the log have any messages about re-merging?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think it should and you'll always get too many records with the select * approach. Try listing just the fields you want to keep explicitly including month. FYI - I don't think month is the correct grouping level unless you want monthly averages over the 10 years because I'm pretty sure that's what is happening. So you have a single average for all of January, not an average for January 2011, January 2012 etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/275712"&gt;@drshashlik&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I need to select the first day of each month for multiple years. I have daily admissions for 10 years.&amp;nbsp; I need this collapsed into one row for the first date of each month over the ten years.&amp;nbsp; Ultimately, I need only 120 rows rather than 3650 rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have summed daily admissions (to hospital) for each month of each year.&amp;nbsp; This gives me one column with the total admissions by month/year, but a row for each day of that month.&amp;nbsp; When I try proc sort with no dupkey by month(date) it fails at the nodupkey step.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*Step 1 - works fine*/&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table WANT_1 as select *,&lt;BR /&gt;case when eventid&amp;gt;0 then count(eventid) else . end as monthly_admissions&lt;BR /&gt;from HAVE&lt;BR /&gt;group by month(evstdate);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*Step 2 - does not work fine*/&lt;/P&gt;
&lt;P&gt;proc sort data=WANT_1 out=WANT_2 nodupkey ; by month(admission_date); run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At step 2, I get this error message beneath "by month(admission_date)" :&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, ;, -, :, DECENDING, DESCENDING, DESENDING, _ALL_, _CHARACTER_,&lt;BR /&gt;_CHAR_, _NUMERIC_.&lt;/P&gt;
&lt;P&gt;33 proc sort data=count_month out=count_month_a nodupkey ; by month(admission_date); run;&lt;BR /&gt;_&lt;BR /&gt;200&lt;BR /&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anybody help with this?&amp;nbsp; Many, many thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 23:49:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-only-first-day-of-each-month-over-multiple-years/m-p/681180#M36926</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-09-02T23:49:45Z</dc:date>
    </item>
    <item>
      <title>Re: Select only first day of each month over multiple years</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-only-first-day-of-each-month-over-multiple-years/m-p/681184#M36928</link>
      <description>Hi Reeza,&lt;BR /&gt;no, the log does not mention remerging. And you are correct that I am getting the same values for all Januaries, Februaries etc (which is not what I want). I tried specifying the exact variables to select (rather than select *), but that made no difference apart from reducing the number of columns.</description>
      <pubDate>Thu, 03 Sep 2020 00:09:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-only-first-day-of-each-month-over-multiple-years/m-p/681184#M36928</guid>
      <dc:creator>drshashlik</dc:creator>
      <dc:date>2020-09-03T00:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: Select only first day of each month over multiple years</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-only-first-day-of-each-month-over-multiple-years/m-p/681205#M36929</link>
      <description>&lt;P&gt;You can't sort by an expression in proc sort. And you don't need to.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table WANT as 
select 
	intnx("month", evstdate, 0) as monthDate format=yymmdd10.,
	count(eventId) as monthly_admissions
from HAVE
group by calculated monthDate;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested)&lt;/P&gt;</description>
      <pubDate>Thu, 03 Sep 2020 02:55:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-only-first-day-of-each-month-over-multiple-years/m-p/681205#M36929</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-09-03T02:55:47Z</dc:date>
    </item>
    <item>
      <title>Re: Select only first day of each month over multiple years</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-only-first-day-of-each-month-over-multiple-years/m-p/681376#M36933</link>
      <description>&lt;P&gt;You can't use a FUNCTION such as MONTH() in a BY statement. That is causing your error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Collapsed how?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It might help to show some example data and what you expect the output to look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I might start with a guess with something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc freq data=have noprint;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; where eventid&amp;gt;0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; tables evstdate / out=want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; format evstdate yymon. ;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Sep 2020 15:14:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-only-first-day-of-each-month-over-multiple-years/m-p/681376#M36933</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-03T15:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: Select only first day of each month over multiple years</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-only-first-day-of-each-month-over-multiple-years/m-p/681918#M36945</link>
      <description>Thank you PG - that works perfectly.</description>
      <pubDate>Sun, 06 Sep 2020 23:54:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-only-first-day-of-each-month-over-multiple-years/m-p/681918#M36945</guid>
      <dc:creator>drshashlik</dc:creator>
      <dc:date>2020-09-06T23:54:43Z</dc:date>
    </item>
  </channel>
</rss>

