If Then ELse Syntax

Hi EE

I am having difficulty doing the If Then Else statements below due to syntax. Any idea howto work this?

DATA _NULL_;
if %compare(150,100)=0 then do;
  PROC SQL INOBS=10 OUTOBS=10;
        CREATE TABLE WORK.TEST1 AS SELECT * FROM MYLIB.TABLE1;
  QUIT;
else do;
  PROC SQL INOBS=10 OUTOBS=10;
        CREATE TABLE WORK.TEST2 AS SELECT * FROM MYLIB.TABLE2;
  QUIT;
end;
run;
LuckyLucksAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
bradanelsonConnect With a Mentor Commented:
Try removing the COMPARE function you had in the statement.  Are you getting errors?  What does the log say?

%MACRO CreateTest(a,b);
  %if &a^=&b %then %do;
    PROC SQL INOBS=10 OUTOBS=10;
        CREATE TABLE WORK.TEST1 AS SELECT * FROM MYLIB.TABLE1;
    QUIT;
  %end;
  %else %do;
    PROC SQL INOBS=10 OUTOBS=10;
        CREATE TABLE WORK.TEST2 AS SELECT * FROM MYLIB.TABLE2;
    QUIT;
  %end;
%MEND CreateTest;

%CreateTest(150,100);
0
 
bradanelsonConnect With a Mentor Commented:
Try putting the logic in a MACRO.

%MACRO CreateTest();
  %if %compare(150,100)=0 %then %do;
    PROC SQL INOBS=10 OUTOBS=10;
        CREATE TABLE WORK.TEST1 AS SELECT * FROM MYLIB.TABLE1;
    QUIT;
  %end;
  %else %do;
    PROC SQL INOBS=10 OUTOBS=10;
        CREATE TABLE WORK.TEST2 AS SELECT * FROM MYLIB.TABLE2;
    QUIT;
  %end;
%MEND CreateTest;

%CreateTest;

You could get fancy and pass the 2 compare values into the macro aswell.

Good luck.
0
 
LuckyLucksAuthor Commented:
Apparently PROC SQL isnt recognzed inside the macro.
0
All Courses

From novice to tech pro — start learning today.