BookmarkSubscribeRSS Feed
BCNAV
Quartz | Level 8

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);
1 REPLY 1
mkeintz
PROC Star

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.
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1 reply
  • 311 views
  • 0 likes
  • 2 in conversation