The SQL procedure terminates with a segmentation violation error


PROC SQL terminates with a segmentation violation when an inline subquery uses COUNT(1) and the resulting table expression is subsequently joined to one or more additional tables.

Although COUNT(1) and COUNT(*) are logically equivalent in this context, the query fails when you use COUNT(1).

The issue occurs in queries following a pattern similar to the following:

proc sql;
create table origin as select distinct origin from sashelp.cars;
create table x as
select a.n, b.* from
(
select make, count(1) as n from sashelp.cars
group by make
) as a
left join sashelp.cars b
on a.make=b.make
left join origin c
on b.origin=c.origin
where n > 5;
quit;

The expected result is that the query should complete successfully and return the expected result set. However, the actual result is that PROC SQL terminates with a segmentation violation.

Workaround

To work around this issue, replace COUNT(1) with COUNT(*) in the inline subquery.