BookmarkSubscribeRSS Feed
marianaalcos
Quartz | Level 8

Hi there,

 

I have been stuck on this for a while now, so I'll try to get help from the forum again.

I have a dataset which consists of temperature measurements from 1996 to 2015. However, I only have data for 123 days every year (i.e. from July-1st to October-31st). My task is to understand whether there was a change in temperature.

I transformed to time series data by grouping by year and ran Simple and Double Exponential Smoothing. I got my estimates and it was ok.

However, now I want to use HoltWinters (Additive and Multiplicative Seasonality) to get all the 123 seasonal factors (the seasonal factors for each day) and I cannot figure out how (I've done the exact same analysis in R and I was able to declare my timeseries data simply by doing this: myts <- ts(data,start=1996,end=2015,frequency=123), I have no idea how to do this in SAS). 

So I need:

1) Make SAS understands that my frequency is 123 days a year ranging from 1996-2015.

2) Know how to get the seasonal factors (I don't know how to get them either).

 

 

I've attached dataset and the analysis I have so far. Any help would be very much appreciated!

 

/*
 use proc import to assist you importing the file temps.txt */
%let path=/folders/myfolders/hmw;  *defining work directory;
libname hmw "&path"; *assigning a library to store files;


FILENAME REFFILE '/folders/myfolders/hmw/temps.txt';

PROC IMPORT DATAFILE=REFFILE
	DBMS=DLM
	OUT=HMW.temps;
	DELIMITER='09'x; *the hexadecimal representation of Tab in ASCII;
	GETNAMES=YES;
	GUESSINGROWS=100;
RUN;


*PROC CONTENTS DATA=HMW.temps; *RUN; * see some useful info about data;
*title 'The Dataset temps.txt';
*PROC PRINT DATA=HMW.temps;* RUN; *print the data set;
*title;

/* stacking the year columns to make one response column */
data work.__tmp__;
	set HMW.TEMPS;
	_Case_=_n_;
run;
proc transpose data=work.__tmp__ out=WORK.temps_stacked(rename=(col1=Temp)) name=Year;
	var _1996 _1997 _1998 _1999 _2000 _2001 _2002 _2003 _2004 _2005 _2006 _2007 
		_2008 _2009 _2010 _2011 _2012 _2013 _2014 _2015;
	by _Case_;
run;
data WORK.temps_stacked;
	merge work.__tmp__(keep=_Case_ DAY) WORK.temps_stacked;
	drop _Case_;
	by _Case_;
run;
proc delete data=WORK.__tmp__;
run;

/* creating new variable date with format MMDDYY10. */
data WORK.TEMPS_STACKED;
	length Year $ 8;
	set WORK.TEMPS_STACKED;
	select (Year);
		when ('_1996') Year='1996';
		when ('_1997') Year='1997';
		when ('_1998') Year='1998';
		when ('_1999') Year='1999';
		when ('_2000') Year='2000';
		when ('_2001') Year='2001';
		when ('_2002') Year='2002';
		when ('_2003') Year='2003';
		when ('_2004') Year='2004';
		when ('_2005') Year='2005';
		when ('_2006') Year='2006';
		when ('_2007') Year='2007';
		when ('_2008') Year='2008';
		when ('_2009') Year='2009';
		when ('_2010') Year='2010';
		when ('_2011') Year='2011';
		when ('_2012') Year='2012';
		when ('_2013') Year='2013';
		when ('_2014') Year='2014';
		when ('_2015') Year='2015';
		otherwise Year=Year;
	end;
	date_concat =cats(DAY,'-', Year);
    date = input(date_concat,DATE11.);
    format date MMDDYY10.;
    drop date_concat; 
RUN;

/* run this in case you want to check the results for the above proc */
*proc print data=WORK.temps_stacked;
*run;


/* preparing time series data */
title "Time Series Data 'myts'";
proc sort data=WORK.TEMPS_STACKED out=Work.preProcessedData;
	by YEAR date;
run;

proc timedata data=Work.preProcessedData out=WORK.myts;
	by year;
	id date interval=day setmissing=missing;
	var Temp / accumulate=none transform=none;
run;

proc print data=WORK.myts;run;
title;
proc delete data=Work.preProcessedData;run;



/* equations for all methods used below can be found here:
http://support.sas.com/documentation/cdl/en/etsug/68148/HTML/
default/viewer.htm#etsug_tffordet_sect021.htm 
and more info about output here:
http://support.sas.com/documentation/cdl/en/etsug/63348/HTML/
default/viewer.htm#etsug_tffordet_sect013.htm*\

/* Single Exponential Smoothing */
*ods trace on;  /*use this to check the names for all output tables */
title 'Single Exponential Smoothing';
title2 'Only Level Smoothing Weight';
ods select ParameterEstimates; /* selecting tables to be displayed */
proc esm data=WORK.myts back=0 lead=1 print=all plot=none;
	forecast Temp / alpha=0.05 model=simple transform=none;
run;
title;
*ods trace off;

/* The best value of the level smoothing weight (alpha) found is 0.8396301.
   For simple exponential smoothing, a level weight near zero implies 
   that simple differencing of the time series might be appropriate,
   which is not the case here. */

/* Double Exponential Smoothing */
title 'Double Exponential Smoothing';
title2 'Level and Trend Smoothing Weights';
ods select ParameterEstimates ; /* selecting tables to be displayed */
proc esm data=WORK.myts back=0 lead=1 print=all plot=none;
	forecast Temp / alpha=0.05 model=linear transform=none;
run;
title;

/* The best value of the level smoothing weight (alpha in SAS) found is 0.83905.
   The best value of the trend smoothing weight (gamma in SAS) is 0.001.
   For linear (Holt) exponential smoothing, a level weight near zero implies that
   the smoothed trend is constant (i.e., there isn't really a significant trend)
   and that an ARIMA model with deterministic trend might be a more appropriate */

/* Triple Exponential Smoothing */
title 'Triple Exponential Smoothing';
title2 'Additive Seasonality Exponential Smoothing';
ods select ParameterEstimates; /* selecting tables to be displayed */
proc esm data=WORK.myts back=0 lead=1 plot=none print=all;
	id date interval=day setmissing=missing;
	forecast Temp / alpha=0.05 model=ADDWINTERS transform=none;
run;
title;

 

3 REPLIES 3
pau13rown
Lapis Lazuli | Level 10

"My task is to understand whether there was a change in temperature, so I want to predict new temperatures for each of the days in the interval July-1st to October-31st of the consecutive year (2016)." - i don't think this follows. I don't know why you'd what to predict 2016 values when the expressed objective is to estimate the trend over time for temp

marianaalcos
Quartz | Level 8
Yes, Paul.

After your comments I re-stated my objective, because it wasn't really making sense. So, I want to understand whether there was a change in temperature and for that I want to get the 123 seasonal factors to run a CUSUM analysis.
pau13rown
Lapis Lazuli | Level 10

ok, that's outside my area of expertise and i leave it for someone else Smiley Happy

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 725 views
  • 0 likes
  • 2 in conversation