<?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 Looping and Tables for Seasonal Adjustment in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Looping-and-Tables-for-Seasonal-Adjustment/m-p/373451#M276203</link>
    <description>&lt;P&gt;Hello everyone. I have many variables to seasonal adjust, and then merge into one dataset. I can use the attached code, but then I need to use EG to merge them alltogether into a time series database. This is a pain in EG and I'm hoping it can be done within the maco code automatically. The first datastep sets up the data file I want to use, then as the macro goes, I would like to place the seasonally adjusted series into that database. I am stuck as to how to automatically update the database file after every loop iteration. Any suggestions are welcome.&amp;nbsp; Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data EGTASK.NAV_TIME_SERIES_ALL_SA_TS;
	set EGTASK.NAV_TIME_SERIES_ALL_TS (keep=date year month index); run;

%macro seasonal_adj (sa_list=);
%local n i;
%do n=1 %to %sysfunc(countw(&amp;amp;sa_list));
	%let i=%scan(&amp;amp;sa_list,&amp;amp;n);

	proc x11 data=EGTASK.NAV_TIME_SERIES_ALL_TS noprint;
		monthly date=Date;
		var &amp;amp;i;
		output out=&amp;amp;i._sa
			A1=&amp;amp;i
			/* D10 is really multiplied by 100, so divide these by 100 in a spreadsheet */
			D10=&amp;amp;i._SF
			D11=&amp;amp;i._SA; run;
%end;
%mend;
%seasonal_adj (sa_list=TERM_ECU TERM_ECU_M11 TERM_ECU_M22 TERM_ECU_M33 TERM_ECU_M34 TERM_ECU_M35 TERM_AMT TERM_AMT_M11
					   TERM_AMT_M22 TERM_AMT_M33 TERM_AMT_M34 TERM_AMT_M35 ENR_ECU ENR_ECU_M11 ENR_ECU_M22 ENR_ECU_M33
					   ENR_ECU_M34 ENR_ECU_M35 ENR_AMT ENR_AMT_M11 ENR_AMT_M22 ENR_AMT_M33 ENR_AMT_M34 ENR_AMT_M35 OV_ECU
					   OV_ECU_KTOK OV_ECU_M11 OV_ECU_M14 OV_ECU_M22 OV_ECU_M23 OV_ECU_M24 OV_ECU_M45 OV_ECU_M46
					   OV_ECU_OTHER_SUM OV_AMT OV_AMT_KTOK OV_AMT_M11 OV_AMT_M14 OV_AMT_M22 OV_AMT_M23
					   OV_AMT_M24 OV_AMT_M45 OV_AMT_M46 OV_AMT_OTHER_SUM);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 05 Jul 2017 22:29:41 GMT</pubDate>
    <dc:creator>BCNAV</dc:creator>
    <dc:date>2017-07-05T22:29:41Z</dc:date>
    <item>
      <title>Looping and Tables for Seasonal Adjustment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-and-Tables-for-Seasonal-Adjustment/m-p/373451#M276203</link>
      <description>&lt;P&gt;Hello everyone. I have many variables to seasonal adjust, and then merge into one dataset. I can use the attached code, but then I need to use EG to merge them alltogether into a time series database. This is a pain in EG and I'm hoping it can be done within the maco code automatically. The first datastep sets up the data file I want to use, then as the macro goes, I would like to place the seasonally adjusted series into that database. I am stuck as to how to automatically update the database file after every loop iteration. Any suggestions are welcome.&amp;nbsp; Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data EGTASK.NAV_TIME_SERIES_ALL_SA_TS;
	set EGTASK.NAV_TIME_SERIES_ALL_TS (keep=date year month index); run;

%macro seasonal_adj (sa_list=);
%local n i;
%do n=1 %to %sysfunc(countw(&amp;amp;sa_list));
	%let i=%scan(&amp;amp;sa_list,&amp;amp;n);

	proc x11 data=EGTASK.NAV_TIME_SERIES_ALL_TS noprint;
		monthly date=Date;
		var &amp;amp;i;
		output out=&amp;amp;i._sa
			A1=&amp;amp;i
			/* D10 is really multiplied by 100, so divide these by 100 in a spreadsheet */
			D10=&amp;amp;i._SF
			D11=&amp;amp;i._SA; run;
%end;
%mend;
%seasonal_adj (sa_list=TERM_ECU TERM_ECU_M11 TERM_ECU_M22 TERM_ECU_M33 TERM_ECU_M34 TERM_ECU_M35 TERM_AMT TERM_AMT_M11
					   TERM_AMT_M22 TERM_AMT_M33 TERM_AMT_M34 TERM_AMT_M35 ENR_ECU ENR_ECU_M11 ENR_ECU_M22 ENR_ECU_M33
					   ENR_ECU_M34 ENR_ECU_M35 ENR_AMT ENR_AMT_M11 ENR_AMT_M22 ENR_AMT_M33 ENR_AMT_M34 ENR_AMT_M35 OV_ECU
					   OV_ECU_KTOK OV_ECU_M11 OV_ECU_M14 OV_ECU_M22 OV_ECU_M23 OV_ECU_M24 OV_ECU_M45 OV_ECU_M46
					   OV_ECU_OTHER_SUM OV_AMT OV_AMT_KTOK OV_AMT_M11 OV_AMT_M14 OV_AMT_M22 OV_AMT_M23
					   OV_AMT_M24 OV_AMT_M45 OV_AMT_M46 OV_AMT_OTHER_SUM);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Jul 2017 22:29:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-and-Tables-for-Seasonal-Adjustment/m-p/373451#M276203</guid>
      <dc:creator>BCNAV</dc:creator>
      <dc:date>2017-07-05T22:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: Looping and Tables for Seasonal Adjustment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-and-Tables-for-Seasonal-Adjustment/m-p/373492#M276204</link>
      <description>&lt;P&gt;Instead of embedding the PROC X11 in a loop, embed 2 loops (one for D10, one for D11) inside the proc X11.&amp;nbsp; Then one data set will have all you want.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data EGTASK.NAV_TIME_SERIES_ALL_SA_TS;
  set EGTASK.NAV_TIME_SERIES_ALL_TS (keep=date year month index);
run;

%macro seasonal_adj (sa_list=);
  %local n i;
  %let N=%sysfunc(countw(&amp;amp;sa_list));

  proc x11 data=EGTASK.NAV_TIME_SERIES_ALL_TS noprint;
    monthly date=Date;
    VAR &amp;amp;sa_list;
    OUTPUT  out=ALL_SA 
      A1= &amp;amp;sa_list
      D10=%do i=1 %to &amp;amp;N; %scan(&amp;amp;sa_list,&amp;amp;I)_SF %end;
      D11=%do i=1 %to &amp;amp;N; %scan(&amp;amp;sa_list,&amp;amp;I)_SA %end;
    ; 
  run;
%mend;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notes:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Run this once with just 2 or 3 vars in SA_LIST, for testing&lt;/LI&gt;
&lt;LI&gt;Put an&lt;BR /&gt;&amp;nbsp; OPTIONS MPRINT:&lt;BR /&gt;statement prior to the macro call, so you can see how sas interprets the macros.&lt;/LI&gt;
&lt;LI&gt;Note there are semi-colons for each %end statement, and then an addition semicolon to terminate the OUTPUT statement.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Thu, 06 Jul 2017 02:23:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-and-Tables-for-Seasonal-Adjustment/m-p/373492#M276204</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-07-06T02:23:26Z</dc:date>
    </item>
  </channel>
</rss>

