Looping and Tables for Seasonal Adjustment

Reply
Contributor
Posts: 23

Looping and Tables for Seasonal Adjustment

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.  Thanks!

 

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(&sa_list));
	%let i=%scan(&sa_list,&n);

	proc x11 data=EGTASK.NAV_TIME_SERIES_ALL_TS noprint;
		monthly date=Date;
		var &i;
		output out=&i._sa
			A1=&i
			/* D10 is really multiplied by 100, so divide these by 100 in a spreadsheet */
			D10=&i._SF
			D11=&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);
Super User
Posts: 789

Re: Looping and Tables for Seasonal Adjustment

Instead of embedding the PROC X11 in a loop, embed 2 loops (one for D10, one for D11) inside the proc X11.  Then one data set will have all you want. 

 

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(&sa_list));

  proc x11 data=EGTASK.NAV_TIME_SERIES_ALL_TS noprint;
    monthly date=Date;
    VAR &sa_list;
    OUTPUT  out=ALL_SA 
      A1= &sa_list
      D10=%do i=1 %to &N; %scan(&sa_list,&I)_SF %end;
      D11=%do i=1 %to &N; %scan(&sa_list,&I)_SA %end;
    ; 
  run;
%mend;

 

Notes:

  1. Run this once with just 2 or 3 vars in SA_LIST, for testing
  2. Put an
      OPTIONS MPRINT:
    statement prior to the macro call, so you can see how sas interprets the macros.
  3. Note there are semi-colons for each %end statement, and then an addition semicolon to terminate the OUTPUT statement.
Ask a Question
Discussion stats
  • 1 reply
  • 120 views
  • 0 likes
  • 2 in conversation