Plots loop in macro

Reply
Contributor
Posts: 27

Plots loop in macro

Hi everyone,

I'm trying to build a macro who plots several fits depending on the degree of freedom in a proc gam. Here are my code:

%LET df_ind = 4;

%MACRO PlotFit;

%do &df_ind=4 %to 15;

PROC GAM data= C.one;

model cost=spline(age,df=&df_ind)/DIST=GAMMA;

output out=C.Fit&df_ind_M p;

run;

title "Fit with df=&df_ind";

proc gplot C.Fit&df_ind_M;

plot P_cost*age cost*age/overlay;

symbol interpol=join l=1 w=2;

run;

%end;

%MEND PlotFit;

%PlotFit;

The problem is: there's just one fit in my output (corresponding to df_in=4). I don't understand why I haven't a fit for each value of df_ind from 4 to 15. I'm quite new with SAS macro so excuse my lack of knowledge!Loop

Thanks in advance,

Arnaud

Super Contributor
Posts: 644

Re: Plots loop in macro

Couple of things to note just looking at your code

  1. The statement %LET df_ind = 4; achieves nothing.  But I doubt it has any impact on the result.
  2. It looks like you are trying to create individual datasets for each value of df_in.  But the dataset name has to be C.Fit&df_ind._M with a period (dot) after df_ind.  Other wise SAS will look for a macro variable &df_ind_M which is undefined. 

Can you show us the log? At least the part which reports any errors or warnings, and the note(s) relating to any output tables that are created.

Richard in Oz

Contributor
Posts: 27

Re: Plots loop in macro

Posted in reply to RichardinOz

Hi Richard in Oz,

I corrected my code with your remarks. The log is just the code lines of my macro. There is no error/warning...

Thanks for your answer,

Arnaud

Super User
Super User
Posts: 7,078

Re: Plots loop in macro

Since the last line is a call to the macro then you should see notes and messages as it tries to run it.  If you are not then you probably have unbalanced quotes, parenthesis or other things that is causing to not see the macro call.  Sometimes it is easiest to just save your program, close SAS and start over to clear up that type of issue.

Super Contributor
Posts: 543

Re: Plots loop in macro

Hi.

There were a couple of errors in your code.

As said before the

%let df_ind = 4 confuses SAS, because in your macro you start with a DO-LOOP that resolves to;

     do 4 = 4 to 15;

Nonsense.

So I modified your code (I used sashelp.class as data set since I didn't have your data)


First, in the DO-LOOP your df_ind is not a macro variable for the macro PlotFit.

I added a PROC SORT so I can make some meaning in what I am plotting;

I added a "data =" in your PROC GPLOT;

(Please note that you need to change the bolded text in the code below)


%MACRO PlotFit;

%do df_ind=2 %to 3;

PROC GAM data= sashelp.class;

model weight=spline(age,df=&df_ind.)/DIST=GAMMA;

output out=Fit&df_ind._M p;

run;

proc sort data = Fit&df_ind._M;by p_weight;

title "Fit with df=&df_ind.";

proc gplot data =  Fit&df_ind._m;

plot P_weight*age weight*age/overlay;

symbol interpol=join l=1 w=2;

run;quit;

%end;

%MEND PlotFit;

%PlotFit;

Best of luck!

Anca.

Ask a Question
Discussion stats
  • 4 replies
  • 541 views
  • 9 likes
  • 4 in conversation