BookmarkSubscribeRSS Feed
deleted_user
Not applicable
When using the code below it creates the table even if no records are returned. Is there a way to tell to to only create the table if records are returned as the result of the WHERE clause? I want to use the table creation itself as a trigger for other processes



PROC SQL;
CREATE TABLE work.STF_2001 AS SELECT
QUERY3723.Trigger
FROM WORK.QUERY3723 AS QUERY3723
WHERE QUERY3723.Trigger = 0;
QUIT;
5 REPLIES 5
deleted_user
Not applicable
Hi Joel,

I think you no need to mention Work library. If you dont save the dataset in permament library , default it will save it on work library.

Try this,
Proc Sql;
create table STF_2002
as
select Q.Trigger
from QUERY3723 AS Q where Q.Trigger=0;
Quit;

Thanks,
Raj
DBailey
Lapis Lazuli | Level 10
I think the DDL to create the table happens before the query is actually performed. For some codes, that's a shortcut to duplicate the table structure without copying data. For example, if you say
create table TABA as select * from TABB where 1=2;

You will get a copy of the table structure without any data.

I would think you'll have to use macros to check and see if there are records that match your criteria and only then would you create the table.
deleted_user
Not applicable
that's what I was thinking -

I don't need a specifically a proc SQL -

a SAS data step would work as well -

but what I need is a macro that checks the tabel for records -

if there are some it creates TableA and if not TableB

anyone have a sample macro that does that?
LinusH
Tourmaline | Level 20
You could use something like:
proc sql;

%macro ConditionalCreate;

select count(*) into: macrovar
from a
where b=c
;
quit;

%if &macrovar ne 0 %then %do;

proc sql;
create table
...

;
quit;
%end;
%mend ConditionalCreate;

%ConditionalCreate;

/Linus
Data never sleeps
deleted_user
Not applicable
Hi Linus

Excellent worked perfectly!

Thanks - Joel

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1188 views
  • 0 likes
  • 3 in conversation