Regarding the likely issue being that arrays are not permanent object and can not be referred to after the data step completes: I am not using the array outside the datastep. I am only using it within the datastep. Also, within the datastep I can do temp = myarray1(1); and I can do %dograph(Age,LoanSmall); But I can not do: %dograph(myarray1(1),LoanSmall); The macro produces some formatted png image files with standardized naming to be read into the Latex document. Before doing that it also collapses the data by some appropriate averages according to the first argument passed (either Age or Date). There will be many douzens of these image files, and the macro will be called from many different parts of the code. Right now somebody is using this code by copying and pasting hardcoded macro calls with actual variable names about 40 times. "%dograph(Age,LoanSmall), %dograph(Age,LoanLarge), etc. In reality there are many more loan types. For now, I just want a way of looping through the variables for the first and second argument. below I will put a stripped down version of the macro. As I mentioned, the macro itself works when called like this: %dograph(Age,LoanSmall); The short version of the macro. It is possible that this macro can be streamlined and improved. But it is being used successfully in production for a while and does work when calling directly with variable names. I do not want to change the macro - it is not mine. I just want to be able to call it as a loop, the way I can do it in STATA, R, Matlab and many other languages. %macro dograph(AgeorDate,loantype); data subset; set summary; run; PROC FORMAT; VALUE genderval 0="All" 1="Couple" 2="Male" 3="Female"; RUN; data subset0; set subset; if female=1 then gender = 3; if male = 1 then gender = 2; if couple = 1 then gender = 1; FORMAT gender genderval.; LABEL smm = "SMM"; LABEL loanage = "Loan Age in Months"; run; data subsets; set subset0; gender = 0; run; proc datasets; append base= subsets data= subset0; Proc sort data= subsets; by gender &AgeorDate ; run; proc means data= subsets noprint; var smm fit; by gender &AgeorDate; weight _weight_; output out=lalas; run; data lalas; set lalas; if _STAT_='MEAN'; run; goptions reset=index device=png gsfname=graphout; ods graphics on / width = 5.25in outputfmt= png imagemap = on reset = index imagename="IJMy_&AgeorDate" border=off; ods listing gpath="/sasmart/zkydmjo/IJGraph"; ods graphics on / width=6.75in height=5.25in; PROC SGPANEL DATA=lalas; PANELBY gender /SPACING=3 novarname; series y=smm x=&AgeorDate / MARKERS MARKERATTRS = (SYMBOL = CircleFilled COLOR = black SIZE = 5) LINEATTRS = (COLOR = black PATTERN = SOLID); series y=fit x=&AgeorDate / MARKERS MARKERATTRS = (SYMBOL = circle COLOR = green SIZE = 5) LINEATTRS = (COLOR = green PATTERN = SOLID); COLAXIS grid; ROWAXIS grid; RUN; ods listing close; %mend dograph;
... View more