BookmarkSubscribeRSS Feed
arnaudd
Calcite | Level 5

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

4 REPLIES 4
RichardinOz
Quartz | Level 8

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

arnaudd
Calcite | Level 5

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

Tom
Super User Tom
Super User

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.

AncaTilea
Pyrite | Level 9

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1125 views
  • 9 likes
  • 4 in conversation