Hi all, I have some questions on the below code : I have 2 time series data sets: data and data_lags, say. The first has say 5 variables (Unemployment, GDP etc) and the second has the same variables lagged. I need a macro ( transf_YoY below) that will create the YoY growth rate for each variable. The respective variables are in the same order in both data sets(unemp first, GDP next etc). I have embedded 2 calls to Proc SQL inside the macro that will change the data set variables into macro variables. Next, I create macro variables indexed by a counter i, corresponsing to each of the variables in data and data_lags. Finally, inside a Do loop, I perform the YoY transoformation, by taking the difference of the ith variable with its lagged version. In fact, it is in order to perform the transformation inside a loop systematically that I needed to create the indexed vairables in the previous step. I needed to separate the original and the lagged variables into 2 different datasets since the lag and dif functions are not available within a macro function. My questions are: Can I use Proc SQL inside a macro as I have done here? Also, how do I export the transformed YoY variables to a new data set or append it to the original data from inside the macro transf_YoY? Is the logic below look right? I don't have immediate access to SAS, and would be thankful for any advice. %macro transf_YoY( data, data_lags) ## Step 1 ## Use Select Into to create macro variables corresponding to data set variables proc sql noprint; select Unemp, GDP into: Unemp, :GDP from &data; select lagUnemp, lagGDP into: lagUnemp, :lagGDP from &data_lags; ## Step 2 ## Create macro variable names indexed by "i" so as to do the YoY transform inside a loop. ## First, do the indexing for the original variables %let dsid = %sysfunc (open(&data)) %let i = 1; %do i = 1 %to 5; %let var&i = %sysfunc(varname(&dsid, &i)) %end; %let close = %sysfunc(close(&dsid)) ## Next, do the indexing for the lagged variables %let dsid = %sysfunc (open(&data_lags)) %let i = 1; %do i = 1 %to 5; %let lagvar&i = %sysfunc(varname(&dsid, &i)); %end; %let close = %sysfunc(close(&dsid)); ## Create YoY transformation using &var_i and & lagvar_i created above ## The final YoY transformed variables are in YoY_var_&i %do i = 1 %to 5; %let YoY_var_&i = (&&var&i - &&lagvar&i)/ &&lagvar&i; %end; %mend; Thank you, Radhika
... View more