<?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: Macro to pass year and quarter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-pass-year-and-quarter/m-p/919860#M362315</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/464406"&gt;@Sas_rookie_sa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I have a data set with dates from all year long. I'm trying to set up a macro to pass a sysparm to only evaluate data with a given year and a given quarter&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Are you going to do this repeatedly, such that all year/quarter combinations in your data set are "evaluated" (whatever that means)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No need for a macro in this case. This will get the job done (it is calculating means, but other statistics are available):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have nway;
     class date;
     var amount;
     format date yyq6.;
     output out=want mean=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In fact, this seems like a more efficient approach than repeatedly calling a macro, it should execute much faster, especially on large data sets. Please explain how you would use such a macro.&lt;/P&gt;</description>
    <pubDate>Mon, 11 Mar 2024 21:34:48 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2024-03-11T21:34:48Z</dc:date>
    <item>
      <title>Macro to pass year and quarter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-pass-year-and-quarter/m-p/919832#M362309</link>
      <description>I have a data set with dates from all year long. I'm trying to set up a macro to pass a sysparm to only evaluate data with a given year and a given quarter</description>
      <pubDate>Mon, 11 Mar 2024 19:25:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-pass-year-and-quarter/m-p/919832#M362309</guid>
      <dc:creator>Sas_rookie_sa</dc:creator>
      <dc:date>2024-03-11T19:25:11Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to pass year and quarter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-pass-year-and-quarter/m-p/919838#M362312</link>
      <description>&lt;P&gt;Something like this should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	call streaminit(12345);
	do date='01JAN2022'd to '31DEC2024'd by 7;
		Amount =rand('integer', 100, 200);
		output;
	end;
run;

%macro summarize4(year, qtr);
proc sql;
	select "&amp;amp;year" as Year
			,"&amp;amp;qtr" as Quarter
			,sum(Amount) as Total
			,round(avg(Amount),.1) as Average
		from have
		where year(date)=&amp;amp;year
		 and qtr(date)=&amp;amp;qtr
;
quit;
%mend;

%summarize4(2023,2)
%summarize4(2024,1)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Result:&lt;/STRONG&gt;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure SQL: Query Results" frame="box" rules="all" cellspacing="0" cellpadding="5"&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="l b header" scope="col"&gt;Year&lt;/TH&gt;
&lt;TH class="l b header" scope="col"&gt;Quarter&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;Total&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;Average&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;2023&lt;/TD&gt;
&lt;TD class="l data"&gt;2&lt;/TD&gt;
&lt;TD class="r data"&gt;2020&lt;/TD&gt;
&lt;TD class="r data"&gt;155.4&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="branch"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BR /&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure SQL: Query Results" frame="box" rules="all" cellspacing="0" cellpadding="5"&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="l b header" scope="col"&gt;Year&lt;/TH&gt;
&lt;TH class="l b header" scope="col"&gt;Quarter&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;Total&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;Average&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;2024&lt;/TD&gt;
&lt;TD class="l data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;1934&lt;/TD&gt;
&lt;TD class="r data"&gt;148.8&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2024 19:46:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-pass-year-and-quarter/m-p/919838#M362312</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2024-03-11T19:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to pass year and quarter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-pass-year-and-quarter/m-p/919860#M362315</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/464406"&gt;@Sas_rookie_sa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I have a data set with dates from all year long. I'm trying to set up a macro to pass a sysparm to only evaluate data with a given year and a given quarter&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Are you going to do this repeatedly, such that all year/quarter combinations in your data set are "evaluated" (whatever that means)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No need for a macro in this case. This will get the job done (it is calculating means, but other statistics are available):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have nway;
     class date;
     var amount;
     format date yyq6.;
     output out=want mean=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In fact, this seems like a more efficient approach than repeatedly calling a macro, it should execute much faster, especially on large data sets. Please explain how you would use such a macro.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2024 21:34:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-pass-year-and-quarter/m-p/919860#M362315</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-03-11T21:34:48Z</dc:date>
    </item>
  </channel>
</rss>

