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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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
  • 5 replies
  • 868 views
  • 0 likes
  • 3 in conversation