<?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: Merging Forecast Tables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merging-Forecast-Tables/m-p/367065#M275281</link>
    <description>&lt;P&gt;If you are talking about combining data sets from this point in your code:&lt;/P&gt;
&lt;PRE&gt;proc sql;
           create table egtask.hist_fcst_HW_&amp;amp;i as
                select date,&amp;amp;i._TCU8 from EGTASK.AIRPORT8_TERM_TS
                outer union corr
                select date,&amp;amp;i._TCU8 from WORK.FCST_Winters_Auto_&amp;amp;i; run;
proc sql;
           create table egtask.hist_fcst_STEPLIN_&amp;amp;i as
                select date,&amp;amp;i._TCU8 from EGTASK.AIRPORT8_TERM_TS
                outer union corr
                select date,&amp;amp;i._TCU8 from WORK.FCST_Stepar_LT_&amp;amp;i; run;

%end;

%mend;
&lt;/PRE&gt;
&lt;P&gt;I might suggest addint two data steps at AFTER the %end of the loop that look like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%end;
data  egtask.hist_fcst_HW_Final;
  set  egtask.hist_fcst_HW_: ;
run;

data  egtask.hist_fcst_STEPLIN_final;
  set  egtask.hist_fcst_STEPLIN_: ;
run;
%mend;&lt;/PRE&gt;
&lt;P&gt;The : at the end of the base of your file name says to set all of the data sets starting with that name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Jun 2017 17:18:47 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-06-14T17:18:47Z</dc:date>
    <item>
      <title>Merging Forecast Tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-Forecast-Tables/m-p/367050#M275280</link>
      <description>&lt;P&gt;Hi all. I am using the following program to generate simple forecasts for airport data. It all works fine and end up with all I need. Specifially, I use the sql commands to generate a table of history and forecasts (by month) for each airport code. It occured to me that it would be easier for exporting and other analysis if I could merge each forecast on the fly in the&amp;nbsp;do loop to a MERGE_FCST table and have all forecasts in one spot (then delete the temporary tables). I cannot figure out out to accomplish this within my program. Each of the individual tables has a date column and a forecast column. I would like to merge all forecasts into one MERGE_FCST table with one date column and then the airport history/forecast column side by side. Thanks for any help.&lt;/P&gt;&lt;P&gt;Bill&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt; forecast_hw (airport_list=);&lt;/P&gt;&lt;P&gt;/*&lt;/P&gt;&lt;P&gt;Macro language does not use quotes around the values of macro variables&lt;/P&gt;&lt;P&gt;Macro language %DO loops are limited, and can iterate over a range of numeric values only&lt;/P&gt;&lt;P&gt;*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ods tagsets.sasreport13(id=EGSR) gtitle gfootnote; /* This ensures titles go into graph area */&lt;/P&gt;&lt;P&gt;%let hist_date='01apr2017'd;&lt;/P&gt;&lt;P&gt;%let length_fcst=12;&lt;/P&gt;&lt;P&gt;%local n i;&lt;/P&gt;&lt;P&gt;%do n=&lt;STRONG&gt;1&lt;/STRONG&gt; %to %sysfunc(countw(&amp;amp;airport_list));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let i=%scan(&amp;amp;airport_list,&amp;amp;n);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* --------------------------------------- FORECASTING --------------------------------------- */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Do regular HW Model for forecasting */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc forecast data=EGTASK.AIRPORT8_TERM_TS method=winters interval=month trend=&lt;STRONG&gt;2&lt;/STRONG&gt; alpha=&lt;STRONG&gt;0.05&lt;/STRONG&gt; seasons=month lead=&amp;amp;length_fcst nstart=max nsstart=max out=FCST_Winters_Auto_&amp;amp;i outest=Est_Winters_Auto_&amp;amp;i;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; id date;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var &amp;amp;i._TCU8;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where date &amp;lt;= &amp;amp;hist_date; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Do STEPAR Model for forecasting with linear trend */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc forecast data=EGTASK.AIRPORT8_TERM_TS method=stepar interval=month trend=&lt;STRONG&gt;2&lt;/STRONG&gt; alpha=&lt;STRONG&gt;0.05&lt;/STRONG&gt; lead=&amp;amp;length_fcst nlags=&lt;STRONG&gt;13&lt;/STRONG&gt; out=FCST_Stepar_LT_&amp;amp;i outest=Est_Stepar_LT_&amp;amp;i;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; id date;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var &amp;amp;i._TCU8;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where date &amp;lt;= &amp;amp;hist_date; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Do STEPAR Model for forecasting with quadratic trend */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc forecast data=EGTASK.AIRPORT8_TERM_TS method=stepar interval=month trend=&lt;STRONG&gt;3&lt;/STRONG&gt; alpha=&lt;STRONG&gt;0.05&lt;/STRONG&gt; lead=&amp;amp;length_fcst nlags=&lt;STRONG&gt;13 &lt;/STRONG&gt;out=FCST_Stepar_QT_&amp;amp;i outest=Est_Stepar_QT_&amp;amp;i;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; id date;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var &amp;amp;i._TCU8;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where date &amp;lt;= &amp;amp;hist_date; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* --------------------------------------- CREATE HISTORY &amp;amp; FORECASTS --------------------------------------- */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table egtask.hist_fcst_HW_&amp;amp;i as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select date,&amp;amp;i._TCU8 from EGTASK.AIRPORT8_TERM_TS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outer union corr&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select date,&amp;amp;i._TCU8 from WORK.FCST_Winters_Auto_&amp;amp;i; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table egtask.hist_fcst_STEPLIN_&amp;amp;i as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select date,&amp;amp;i._TCU8 from EGTASK.AIRPORT8_TERM_TS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outer union corr&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select date,&amp;amp;i._TCU8 from WORK.FCST_Stepar_LT_&amp;amp;i; run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;EM&gt;forecast_hw&lt;/EM&gt;&lt;/STRONG&gt; (airport_list=CYVR CYOW CYYZ CYUL);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2017 16:54:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-Forecast-Tables/m-p/367050#M275280</guid>
      <dc:creator>BCNAV</dc:creator>
      <dc:date>2017-06-14T16:54:15Z</dc:date>
    </item>
    <item>
      <title>Re: Merging Forecast Tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-Forecast-Tables/m-p/367065#M275281</link>
      <description>&lt;P&gt;If you are talking about combining data sets from this point in your code:&lt;/P&gt;
&lt;PRE&gt;proc sql;
           create table egtask.hist_fcst_HW_&amp;amp;i as
                select date,&amp;amp;i._TCU8 from EGTASK.AIRPORT8_TERM_TS
                outer union corr
                select date,&amp;amp;i._TCU8 from WORK.FCST_Winters_Auto_&amp;amp;i; run;
proc sql;
           create table egtask.hist_fcst_STEPLIN_&amp;amp;i as
                select date,&amp;amp;i._TCU8 from EGTASK.AIRPORT8_TERM_TS
                outer union corr
                select date,&amp;amp;i._TCU8 from WORK.FCST_Stepar_LT_&amp;amp;i; run;

%end;

%mend;
&lt;/PRE&gt;
&lt;P&gt;I might suggest addint two data steps at AFTER the %end of the loop that look like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%end;
data  egtask.hist_fcst_HW_Final;
  set  egtask.hist_fcst_HW_: ;
run;

data  egtask.hist_fcst_STEPLIN_final;
  set  egtask.hist_fcst_STEPLIN_: ;
run;
%mend;&lt;/PRE&gt;
&lt;P&gt;The : at the end of the base of your file name says to set all of the data sets starting with that name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2017 17:18:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-Forecast-Tables/m-p/367065#M275281</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-06-14T17:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: Merging Forecast Tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-Forecast-Tables/m-p/367094#M275282</link>
      <description>&lt;P&gt;Thanks. Unfortunately that just appends the tables to the existing one. I am hoping to get the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have files for each airport code that look like (one table per airport code, so if I have 30 airports I have 30 tables):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CYOW_HF&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to merge these automaticalling in the loop to end up with:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CYOW_HF&amp;nbsp; &amp;nbsp; CYYZ_HF&amp;nbsp;&amp;nbsp;&amp;nbsp; CYOW_HF, etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using the : way just appends the files to the end of each other with multiple date fields and the data not spread straight across.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2017 18:26:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-Forecast-Tables/m-p/367094#M275282</guid>
      <dc:creator>BCNAV</dc:creator>
      <dc:date>2017-06-14T18:26:43Z</dc:date>
    </item>
    <item>
      <title>Re: Merging Forecast Tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-Forecast-Tables/m-p/367129#M275283</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/142314"&gt;@BCNAV&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks. Unfortunately that just appends the tables to the existing one. I am hoping to get the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have files for each airport code that look like (one table per airport code, so if I have 30 airports I have 30 tables):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CYOW_HF&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to merge these automaticalling in the loop to end up with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CYOW_HF&amp;nbsp; &amp;nbsp; CYYZ_HF&amp;nbsp;&amp;nbsp;&amp;nbsp; CYOW_HF, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using the : way just appends the files to the end of each other with multiple date fields and the data not spread straight across.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The use of those data set names looks like the process could well be done as a by group and not have to loop through anything.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the same : approach on a MERGE statement.&lt;/P&gt;
&lt;P&gt;If you are trying to split one result then look up thread on the fourm.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that doesn't work you'll need to provide some data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do think that the whole approach may be a bit over complicated as having an AIRPORT variable and all of the analysis varaibles with the same name insted of names like CYVR_tcu8 CYOW_tcu8 instead&lt;/P&gt;
&lt;P&gt;Airport tcu8&lt;/P&gt;
&lt;P&gt;CYVR&amp;nbsp; (value)&lt;/P&gt;
&lt;P&gt;CYOW (value)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then one forecast with BY Airport;&lt;/P&gt;
&lt;P&gt;If you want a final report that reads with the airports across at the end then Proc Report or Tabulate will do that fine and the whole process is much easier.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2017 19:46:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-Forecast-Tables/m-p/367129#M275283</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-06-14T19:46:25Z</dc:date>
    </item>
  </channel>
</rss>

