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

I have two function modules VCE and VCM that differs only in the way M is computed and an additional argument CLUSTER. How can I create a single function module that can handle both computations of M?

Thanks,

Raphael

start vce(y,x,b0,b1,p1,p2,v);

... statements here ...

v = (dg(eta,p2)#dg(xb,p1)#(w-mu)/v)##2;

D = diag(v);

M = t(X)*D*X;

return(M);

finish vce;

  start vcm(cluster,y,x,b0,b1,p1,p2,v);

... statements here ...

  M = J(p,p,0);

  v = (dg(eta,p2)#dg(xb,p1)#(w-mu)/v)##2;

  uClx = unique(Cluster);

  do j = 1 to ncol(uClx);

  dx = loc(Cluster = uClx);

  M = M + t(X[dx,])*v[dx]*t(v[dx])*X[dx,];

  end;

return(M);

finish vce;

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

Assuming you have SAS/IML 12.1 (SAS 9.3m2), use optional arguments and the ISSKIPPED function:

start vc(y,x,b0,b1,p1,p2,v, cluster=);

   if isskipped(cluster) then

      return( vce(y,x,b0,b1,p1,p2,v) );

   else

      return( vcm(cluster,y,x,b0,b1,p1,p2,v) );

finish;

View solution in original post

2 REPLIES 2
Rick_SAS
SAS Super FREQ

Assuming you have SAS/IML 12.1 (SAS 9.3m2), use optional arguments and the ISSKIPPED function:

start vc(y,x,b0,b1,p1,p2,v, cluster=);

   if isskipped(cluster) then

      return( vce(y,x,b0,b1,p1,p2,v) );

   else

      return( vcm(cluster,y,x,b0,b1,p1,p2,v) );

finish;

R_Fraser
Calcite | Level 5

Thanks!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 927 views
  • 0 likes
  • 2 in conversation