Hi,
For the code below, please can someone explain the logic (highlighted in red text below)? I'm confused about why the same "score_result" is used for if/then and else?
proc sql;
%if %sysfunc (exist(score_result))
%then insert into score_result;
%else create table score_result as;
select * from test;
quit;
If I wanted to permanently save into a permanently library, with libref "ac", would the code be the options below, or something else?
Option 1
proc sql;
%if %sysfunc (exist(score_result))
%then insert into ac.score_result;
%else create table ac.score_result as;
select * from test;
quit;
Option 2
proc sql;
%if %sysfunc (exist(score_result))
%then insert into score_result;
%else create table ac.score_result as;
select * from test;
quit;
Option 3
proc sql;
%if %sysfunc (exist(ac.score_result))
%then insert into ac.score_result;
%else create table ac.score_result as;
select * from test;
quit;
I would think that you'd want an option 3:
Option 3
proc sql;
%if %sysfunc (exist(ac.score_result))
%then insert into ac.score_result;
%else create table ac.score_result as;
select * from test;
quit;
Art, CEO, AnalystFinder.com
This macro code:
%if %sysfunc (exist(score_result))
%then insert into score_result;
%else create table score_result as;
alternatively either creates the text
insert into score_result
or the text
create table score_result as
which then, after being fed to the SQL compiler, results in two variants of the SQL statement.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.