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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.