Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro array

Status
Not open for further replies.

Chrisbag

Programmer
Feb 13, 2008
2
GB
Hi I am trying to macro up a data step with array in it, however it causes loads of errors. Why is this?

This is the code I am trying to change into a macro:

data test;
set home_calls_stage4;
array stag3(*) Home_Call_Leads_3 date_3 yhat_3 Saturday_3 Sunday_3 xmas_boxing_3 easter_fri_mon_3 bank_hols_3
Mix_NP_3wk_tail_3 Mix_DM_XS_Tail_C_3 Mix_DM_NTG_tail_B_3 Home_DM_all_tailA_3 Home_Search_Total_cost_3;
array stag3s(*) Home_Call_Leads_3s date_3s yhat_3s Saturday_3s Sunday_3s xmas_boxing_3s easter_fri_mon_3s bank_hols_3s
Mix_NP_3swk_tail_3s Mix_DM_XS_Tail_C_3s Mix_DM_NTG_tail_B_3s Home_DM_all_tailA_3s Home_Search_Total_cost_3s;
array stag4(*) Home_Call_Leads_4 date_4 yhat_4 Saturday_4 Sunday_4 xmas_boxing_4 easter_fri_mon_4 bank_hols_4
Mix_NP_4wk_tail_4 Mix_DM_XS_Tail_C_4 Mix_DM_NTG_tail_B_4 Home_DM_all_tailA_4 Home_Search_Total_cost_4;
do i=1 to dim(stag3);
stag4(i)=((stag3(i)/stag3s(i))*sum(money_off)) + stag3(i);
end;
run;
 
I am not sure what you gain by making this code into a macro. Remember Macro compiles before the SAS execution. In real simple terms its a text writer. It writes the SAS code so that when you execute the program the SAS engine can use it.

I use macro to generate SAS statements that either change dynamically or are just too many to write out.

What do hope to acomplish by using macro for this problem. Do you want to have the variables 'written' so that you don't have to write them on the ARRAY statement line? Perhaps, your design calls for this datastep many times. Let us know more of what you hope to accomplish and I could post a solution for you.

Klaz
 
I need to put it into a macro so that if the money_off variable is not present the data step does not execute. From my research it appears a macro is the only way to achieve this. This is just one step in a long process which will eventually be changed into a macro so the array components can be user defined. Hope this help.
 
Does the datastep work on its own? IE not in the macro. If it does, can you also post the macro version and the error messages (you can just copy and paste the log).
One thing you can do to help debugging is insert the line
Code:
options mprint mlogic symbolgen;
before the macro, that'll show you exactly what is going on when the macro runs.

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top