data example;
input x $ y;
datalines;
a 1
c 5
run;
proc sql;
select * from example
where x = 'c';
quit;
proc sql;
select * from example
where x = 'd';
run;
The first PROC SQL will print the result, but the second PROC SQL will print out an empty dataset. If I have dozens of these PROC SQL statements, is there a way to have the PROC SQL print out only if there is a matching record and PROC SQL like the second one not to print anything to the output window? I tried using a Having and Group By. It worked but prints out an extra CNT column.
proc sql;
select x, count(*) as CNT
from example
group by x
having CNT > 0;
quit;
I have thought about creating a new dataset just to store the results and do another PROC SQL to get the result off that dataset. I don't think it's very efficient.
Thanks in advance for your help!
Proc SQL is inefficient for simple printing and Proc print doesn't create output when there is nothing to print because of a WHERE statement.
proc print data=example ;
where x='d';
run;
In Proc SQL there is noprint option, so use it.
Proc sql noprint;
select * from example
where x= 'd';
quit;
70 proc sql; 71 select * from example 72 where x = 'd'; NOTE: No rows were selected. 73 quit;
A note is added to the LOG,
and nothing is printed in the results.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.