BookmarkSubscribeRSS Feed
Justin9
Obsidian | Level 7

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;

 

 

2 REPLIES 2
art297
Opal | Level 21

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

 

Kurt_Bremser
Super User

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.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 497 views
  • 0 likes
  • 3 in conversation