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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 366 views
  • 0 likes
  • 3 in conversation