<?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: Handling Time Variable in Time Series Modeling in SAS Forecasting and Econometrics</title>
    <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Handling-Time-Variable-in-Time-Series-Modeling/m-p/423208#M2920</link>
    <description>&lt;P&gt;So there are several ways to approach this, but your data set is missing necessary information for creating a date variable.&amp;nbsp;&amp;nbsp;You can&amp;nbsp;easily convert these, but you have data that lists five weeks, and then repeats the same weeks, which leads me to the following questions about your data:&amp;nbsp;Are there by variables? Do you know the year?&amp;nbsp; Are these repeated observations for the same set of weeks, or are these different years or&amp;nbsp;just by groups?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also use seasonality=5 on the proc statement, which would tell it that there is a seasonality of 5, as you would guess, but I'm not sure how you're using PROC ESM or ARIMA without a date variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have drafted a little bit of code that could help you, but I am making the assumption that the year is 2017 for all of your date variables and your data is not sorted by week, thus you have repeated observations. You will notice there will be a large gap in data if this spans multiple years&amp;nbsp;since there are 52 weeks in a year and you only have five.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I added this code above your "datalines" statement&lt;/P&gt;
&lt;P&gt;the first line will get the date for the Sunday of the given week, you then add the number of days to get the actual day. There might be a more sophisticated way to do this with multipliers and shifts, but this was the easiest. I added a format to show you the dates will give you the weekday as given. More information on this is given in the ETS doc chapter "&lt;A class="ng-binding" style="text-align: left; color: rgb(69, 130, 236); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: Verdana, sans-serif; font-size: 12px; font-style: normal; font-weight: bold; text-decoration: none; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(224, 225, 243); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px;" href="http://ltxbld02/14.3/en/view_pdf/etsug/intervals.pdf" target="_blank"&gt;Date Intervals, Formats, and Functions&lt;/A&gt;"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;datestart=intnx('week','01JAN2017'd,week);&lt;BR /&gt;actualdate=intnx('day',datestart,weekday-1);&lt;BR /&gt;format datestart&amp;nbsp; actualdate weekdate.;&lt;/P&gt;</description>
    <pubDate>Thu, 21 Dec 2017 20:35:12 GMT</pubDate>
    <dc:creator>Jennifer_beeman</dc:creator>
    <dc:date>2017-12-21T20:35:12Z</dc:date>
    <item>
      <title>Handling Time Variable in Time Series Modeling</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Handling-Time-Variable-in-Time-Series-Modeling/m-p/422945#M2916</link>
      <description>&lt;P&gt;Hello, I have a question about handling the TIME variable in my time series analysis. Hope someone can help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is my data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sales;
input Week weekday Target;
datalines;
1 4 539.577
1 5 224.675
1 6 129.412
2 2 317.12
2 3 210.517
2 4 207.364
2 5 263.043
2 6 248.958
3 2 344.291
3 3 248.428
3 4 281.42
3 5 243.568
3 6 308.178
4 2 363.402
4 3 336.872
4 4 246.992
4 5 308.88
4 6 233.126
5 2 404.38
1 3 298.56
1 4 229.249
1 5 236.304
1 6 297.174
2 2 409.401
2 3 231.035
2 4 238.826
2 5 235.598
2 6 242.112
3 2 490.79
3 3 289.657
3 4 298.459
3 5 323.603
4 3 616.453
4 4 346.035
4 5 307.645
4 6 253.847
5 2 530.944
5 3 333.359
5 4 306.356
1 6 416.83
2 2 415.187
2 3 268.002
2 4 234.503
2 5 234.724
2 6 230.064
3 2 357.394
3 3 259.246
3 4 244.235
3 5 402.607
3 6 255.061
4 2 342.606
4 3 268.64
4 4 188.601
4 5 202.022
4 6 213.509
5 2 316.849
5 3 286.412
5 4 303.447
5 5 304.95
5 6 331.9
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So basically, I have three columns. The first two are the WEEK and WEEKDAY columns. The WEEK column contains the week number and the second column contains the day of the week (e.g. 2=Monday, 3=Tuesday, 4=Wednesday...etc).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just as an example, the first observation has WEEK=1 and WEEKDAY=4. This is the time point for the Wednesday in week 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm modeling the TARGET variable using Proc Arima and Proc ESM. I believe I need one TIME variable for the x-axis. There are in total 60 observations.&amp;nbsp;I did a quick check and saw that the&amp;nbsp;response is substantially higher on Monday and lower on the rest of the week.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm wondering how I can establish the TIME variable that reflects the weekday information. For example, if I treat the TIME simply as something from 1 to 60, I will lose the seasonal component of the data (because there are some missing days due to holiday).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I believe I have two options:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Convert the WEEK and WEEKDAY columns into an actual date column. That should account for the weekday information.&lt;/LI&gt;&lt;LI&gt;Create a new TIME variable that goes from 1 to 60 and use it as my TIME variable on the x-axis. Create dummy input variables for Monday to Friday.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I'm fairly new to time series. Does anyone have any comment about how this situation should be handled?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2017 04:28:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Handling-Time-Variable-in-Time-Series-Modeling/m-p/422945#M2916</guid>
      <dc:creator>kisumsam</dc:creator>
      <dc:date>2017-12-21T04:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: Handling Time Variable in Time Series Modeling</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Handling-Time-Variable-in-Time-Series-Modeling/m-p/423182#M2919</link>
      <description>&lt;P&gt;The best way would be to create a date variable to use for the time axis.&amp;nbsp;You will need rows for the Saturday and Sunday dates with missing values for the target variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can include weekly differencing in estimate statements for fitting the model. The following will evaluate daily differences and weekly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="xis-codeBlock"&gt;identify var=target;
   estimate p=(1 7);&lt;/PRE&gt;
&lt;P&gt;In the forecasting stage, you can use&amp;nbsp;the ID and INTERVAL&amp;nbsp;options to specify it is daily data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The ID and INTERVAL can be specified in the FORECAST statement, for example,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="sascode"&gt;forecast id=date interval=day;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You shouldn't need a dummy variable for weekday after doing this, at least in PROC ARIMA. It should see if weekly differencing helps with the model based on the INTERVAL=DAY option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also find more information here:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://go.documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.3&amp;amp;docsetId=etsug&amp;amp;docsetTarget=etsug_arima_syntax11.htm&amp;amp;locale=en" target="_self"&gt;PROC ARIMA documentation&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC ESM can be approached similarly, except the ID variable is specified in its own statement, for example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="xis-codeBlock"&gt;proc esm data=&amp;lt;input-data-set&amp;gt; out=&amp;lt;output-data-set&amp;gt;;
   id &amp;lt;time-ID-variable&amp;gt; interval=&amp;lt;frequency&amp;gt;;
   forecast &amp;lt;time-series-variables&amp;gt;;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is another link to the&amp;nbsp;&lt;A href="http://go.documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.3&amp;amp;docsetId=etsug&amp;amp;docsetTarget=etsug_esm_gettingstarted.htm&amp;amp;locale=en" target="_self"&gt;PROC ESM documentation&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2017 19:08:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Handling-Time-Variable-in-Time-Series-Modeling/m-p/423182#M2919</guid>
      <dc:creator>solarflare</dc:creator>
      <dc:date>2017-12-21T19:08:53Z</dc:date>
    </item>
    <item>
      <title>Re: Handling Time Variable in Time Series Modeling</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Handling-Time-Variable-in-Time-Series-Modeling/m-p/423208#M2920</link>
      <description>&lt;P&gt;So there are several ways to approach this, but your data set is missing necessary information for creating a date variable.&amp;nbsp;&amp;nbsp;You can&amp;nbsp;easily convert these, but you have data that lists five weeks, and then repeats the same weeks, which leads me to the following questions about your data:&amp;nbsp;Are there by variables? Do you know the year?&amp;nbsp; Are these repeated observations for the same set of weeks, or are these different years or&amp;nbsp;just by groups?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also use seasonality=5 on the proc statement, which would tell it that there is a seasonality of 5, as you would guess, but I'm not sure how you're using PROC ESM or ARIMA without a date variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have drafted a little bit of code that could help you, but I am making the assumption that the year is 2017 for all of your date variables and your data is not sorted by week, thus you have repeated observations. You will notice there will be a large gap in data if this spans multiple years&amp;nbsp;since there are 52 weeks in a year and you only have five.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I added this code above your "datalines" statement&lt;/P&gt;
&lt;P&gt;the first line will get the date for the Sunday of the given week, you then add the number of days to get the actual day. There might be a more sophisticated way to do this with multipliers and shifts, but this was the easiest. I added a format to show you the dates will give you the weekday as given. More information on this is given in the ETS doc chapter "&lt;A class="ng-binding" style="text-align: left; color: rgb(69, 130, 236); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: Verdana, sans-serif; font-size: 12px; font-style: normal; font-weight: bold; text-decoration: none; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(224, 225, 243); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px;" href="http://ltxbld02/14.3/en/view_pdf/etsug/intervals.pdf" target="_blank"&gt;Date Intervals, Formats, and Functions&lt;/A&gt;"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;datestart=intnx('week','01JAN2017'd,week);&lt;BR /&gt;actualdate=intnx('day',datestart,weekday-1);&lt;BR /&gt;format datestart&amp;nbsp; actualdate weekdate.;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2017 20:35:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Handling-Time-Variable-in-Time-Series-Modeling/m-p/423208#M2920</guid>
      <dc:creator>Jennifer_beeman</dc:creator>
      <dc:date>2017-12-21T20:35:12Z</dc:date>
    </item>
  </channel>
</rss>

