Search code examples
sassas-macrosas-iml

How to conditionally define a macro-variable inside proc iml?


I have an issue with combining proc iml, if/then and call symputx. If I run the following code :

proc iml;

call symputx("noif",3);
a=1;
b=&noif;                              /* 1) : works*/
if a=1 then call symputx("withif",1);
if a=1 then print a;                  /* 2) : works */
c=&withif;                            /* 3) : doesn't work */
quit;
%put &withif;                         /* 4) : works */
  • 1) working (and SAS/IML documentation) show I can use call symputxin proc IML

  • 2) working (and SAS/IML documentation) show I can use if/thenin proc IML

  • 3) not working must therefore be due to some issue in combining the three statements.

  • But 4) working shows the call symputx("withif",1) was somehow understood.

What is the proper way to conditionally define a macro-variable inside proc iml ?


Solution

  • Rick Wicklin answered my question on his blog. Basically, I needed to add empty else statements after my if/then blocks for IML to know they were finished.