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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bradanelsonCommented:
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
bradanelsonCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.