Macro sum variable values and get average? HELP

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

Macro sum variable values and get average? HELP

Hello,

 

Can I sum variable values inside macro?

 

Here's my macro code (hope you're ok with the variable names):

 

%macro estimation(imtis,results);
%let eil_imtis_nuo=1; 
	SASFILE &imtis load;

	proc sql noprint;
		select max(imtis)
		into :imciu_sk
		from &imtis;                                                                                                                                                                  
	quit;
	
	%do eil_imtis=&eil_imtis_nuo %to &imciu_sk;
		data x(keep=Xx);
		set &imtis;
		where imtis=&eil_imtis;
	run;

	%wacf(infile=x,
			varts=xx, 
			varws=,
			outfile=acf,
			corr=SPEARMAN,
			kk=4, 
			alpha=0.05);

	%end;
	SASFILE &imtis close;
%mend estimation;

Screen Shot 2016-05-11 at 19.15.29.png

 

 

Here's what I do:

 

1. I generate time series (in this case just 2 with 10 values in each of them)

2. Then I use macro (the code above) to seperate each data sample (it is variable called "imtis" in the picture or "sample" in english).

3. For every separated data sample (imtis=1,2...etc) I call %wacf macro (which calculates ACF for variable XX using SPEARMAN method). Here's that output file I get from %wacf: 

 

Screen Shot 2016-05-11 at 19.22.50.png

 

The problem is that %wacf overwrites those (ACF) values every time it takes new data sample (imtis). So in this case I only get ACF with multiple lags from the last data sample it uses.

 

I need to get an average ACF. Can anyone help? 

 

I use SAS Studio cloud version.

 

 


Screen Shot 2016-05-11 at 19.15.29.png

Accepted Solutions
Solution
‎05-11-2016 02:08 PM
Trusted Advisor
Posts: 1,116

Re: Macro sum variable values and get average? HELP

[ Edited ]

Hello @ascasfaegADGSgs,

 

In the call of macro WACF you could replace outfile=acf by

outfile=acf&eil_imtis

This would avoid the overwriting.

 

Then (i.e. after the %END statement) you can interleave the resulting datasets ACF1, ACF2, ... and finally summarize:

data acf;
set acf:;
by lag;
run;

proc summary data=acf;
by lag;
var acf;
output out=want(drop=_:) mean=;
run;

I assume that you need the average ACF per value of LAG.

 

Edit: removed semicolon from macro argument

View solution in original post


All Replies
Solution
‎05-11-2016 02:08 PM
Trusted Advisor
Posts: 1,116

Re: Macro sum variable values and get average? HELP

[ Edited ]

Hello @ascasfaegADGSgs,

 

In the call of macro WACF you could replace outfile=acf by

outfile=acf&eil_imtis

This would avoid the overwriting.

 

Then (i.e. after the %END statement) you can interleave the resulting datasets ACF1, ACF2, ... and finally summarize:

data acf;
set acf:;
by lag;
run;

proc summary data=acf;
by lag;
var acf;
output out=want(drop=_:) mean=;
run;

I assume that you need the average ACF per value of LAG.

 

Edit: removed semicolon from macro argument

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 377 views
  • 1 like
  • 2 in conversation