2

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 ?

Vincent
  • 955
  • 2
  • 15
  • 32
  • 1
    Within data step and procedures you should get into the habit of using CALL (SYMPUT, SYMGET, etc...). The problem is that %PUT %LET %IF and the such are actually interpreted and evaluated before the procedure or data step begins. I think that if you put the first %PUT &noif before the PROC IML, you should get 3 already. Are you sure the value was initialized to something different? – Frazz May 21 '14 at 13:23
  • 1
    That is not my real code but a -poorly chosen- reproducible example. I just wanted to show that I couldn't use `&withif` but I agree I shouldn't have used `%put`. I'll edit my question, thank you for making me realize it. However, there was a real problem beyond that bad example (that Rick Wicklin already solved). – Vincent May 21 '14 at 13:49

1 Answers1

2

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.

Vincent
  • 955
  • 2
  • 15
  • 32