BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
giulia7
Calcite | Level 5

Hi! I have a problem with my sas code. I use an ods output instruction in a macro variable, and if I run the three proc inside the macro, I have no problems, but when I try to run the macro itself, I always get the same note and nothing works. I've tried any kind of "ods output close/clear" etc, but nothing seems to work and the note always shows up while running the macro.

I'm new to programming here, maybe the code itself is wrong, but I can't understand while it doesn't work inside the macro but it works for itself.

Thanks!

 

My code:

%macro ZINB;
proc countreg data=tot;
where v1;
model v1=t1 t2 t3/dist=zinb; *offset=ltotal;
zeromodel v1 ~ t1 t2 t3/link=logistic;
ods output ParameterEstimates=pe;
run;

proc sql;
select estimate as b0 into: b0
from pe where Parameter= 'Intercept';
select estimate as b1 into: b1
from pe where Parameter= 't1';
select estimate as b2 into: b2
from pe where Parameter= 't2';
select estimate as b3 into: b3
from pe where Parameter= 't3';
select estimate as c0 into: c0
from pe where Parameter= 'Inf_Intercept';
select estimate as c1 into: c1
from pe where Parameter= 'Inf_t1';
select estimate as c2 into: c2
from pe where Parameter= 'Inf_t2';
select estimate as c3 into: c3
from pe where Parameter= 'Inf_t3';
select estimate as k into: k
from pe where Parameter= '_Alpha';
quit;


/* independent random effects */
proc nlmixed data=tot tech=newrap;
where v1;
parms b0=&b0. b1=&b1. b2=&b2. b3=&b3. c0=&c0. c1=&c1.
c2=&c2. c3=&c3. k=&k. su=1 sv=1;
eta = b0 + b1*t1 + b2*t2 + b3*t3 + ltotal + ui;
lambda = exp(eta);
eta_p = c0 + c1*t1 + c2*t1 + c3*t3 + vi;
p0 = 1/(1+exp(-eta_p));

/* define ZINB log likelihood */
if v1=0 then ll = log( p0 + (1-p0)/(1+k*lambda)**(1/k) );
else ll = log((1-p0)) + v1*log(k*lambda) -
(v1+(1/k))*log(1+k*lambda) + lgamma(v1+(1/k))- lgamma(1/k) - lgamma(v1+1);
model v1 ~ general(ll);
random ui vi ~ normal ([0,0], [su*su, 0, sv*sv])
subject=n_geni_ul_mdn;
run;

%mend;
%macro driver ();
%do vi=10001 %to 10149;
%ZINB;

%end;
%mend;

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

At the end.Study this example:

 

%macro PrintIt();
%do i = 1 %to 3;
   proc print data=sashelp.class(obs=3); run;
%end;
%mend;


%PrintIt;

View solution in original post

6 REPLIES 6
Rick_SAS
SAS Super FREQ

Currently, your code repeats the same analysis 149 times, which is probably not what you intended. Some comments:

1. You are using the statement WHERE V1;
 This statement removes missing values (which you probably intend) but also removes obs where v1=0.  Since you are running a ZINB model, this seems strange. Did you mean to write WHERE V1^=.;  Or, since this is in a macro loop, perhaps you meant WHERE V1=&V1; ?

 

2. When you run code in SAS Studio (and maybe some other SAS interfaces) and the code contains an ODS statement, you will get a note that says

NOTE: ODS statements in the SAS Studio environment may disable some output features.

In 99.9% of cases, you don't need to worry about this note. It is there because the interface pushes some SAS code before and after your program to prepare for capturing the output and sending it to the ODS destination. I have never run a program that has failed to work, although I mostly use simple statements such as ODS GRAPHICS, ODS SELECT, and ODS OUTPUT.

I believe you can safely ignore the NOTE.

giulia7
Calcite | Level 5

Thank you for your reply. I'll try to fix the where statement, it works fine with the "v1^=.". 

 

About the ods note.. I don't get any errors which is fine, but it doesn't show anything, and I'm not sure if it has something to do with the ods note (because it is the only one appearing and the program doesn't process for as long as it does when it actually works), or if it's just that it isn't supposed to show anything if I run it inside a macro.

 

I had the code given to me and I was supposed to change it according to the dataset that I'm using, and I don't know if the code was supposed to not show any results, or not. 

 

Thank you again!

Rick_SAS
SAS Super FREQ

The code you posted will not show anything because you haven't run it. You have defined the macro DRIVER, but you need to submit

%driver;

to run it.

 

When you do run it, you will see 150 copies of (the same) analyses COUNTREG and NLMIXED. I suggest you change the macro loop to 

%do vi=10001 %to 10102;

in preparation for debugging the code. As written, you are analyzing the same data over and over. You might want to talk with your supervisor to clarify what the program is supposed to do.

giulia7
Calcite | Level 5

I had the feeling that the code was just analyzing the same data, I'll need to find out more about what is supposed to do.

 

About the %driver;, where am I supposed to place it? I've tried but ti doesn't seem to be any different from before

Rick_SAS
SAS Super FREQ

At the end.Study this example:

 

%macro PrintIt();
%do i = 1 %to 3;
   proc print data=sashelp.class(obs=3); run;
%end;
%mend;


%PrintIt;
giulia7
Calcite | Level 5

It works now! It always runs the same procedure without changing anything, but at least it prints out something and I don't get any errors or notes. I still have to find what I actually am supposed to do with this code, but at least it is "technically fixed".

 

Thank you so much for all the help!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1434 views
  • 0 likes
  • 2 in conversation