BookmarkSubscribeRSS Feed
shanky_44
Obsidian | Level 7

I have very limited understanding of Proc SQl and hoping if someone an help me out here with this code. This is a summary table code. 

 

 

proc sql ;
create table cnts as

select 1 as ord, trt01an, trt01a, count (distinct USUBJID ) as cnt
from ads_1 where enrlfl ="Y" group by trt01an, trt01a
union
select 2 as ord, trt01an, trt01a, count( distinct usubjid) as cnt
from ads_1 where QFELOEYE ne "N/A" group by trt01an, trt01a
union
select 3 as ord, trt01an, trt01a, count( distinct usubjid) as cnt
from ads_1 where QFELOEYE = "N/A" group by trt01an, trt01a
union
select 6 as ord, trt01an, trt01a, count( distinct usubjid) as cnt
from ads_1 where saffl ="Y" group by trt01an, trt01a ;

quit;

3 REPLIES 3
ballardw
Super User

What type of help do you need?

This is counting unique USUBJID within combinations of the variables trt01an and trt01a where different conditions are met (the WHERE) and then stacking the results in a specific order into a data set (union and "value as ord")

shanky_44
Obsidian | Level 7

I was looking for an explanation for the code what is happening along if there is another way to do that without Proc SQL.

PGStats
Opal | Level 21

Unless you can assume that the 4 categories (ord = 1, 2, 3, 6) are mutually exclusive, there is no simple way to replicate this query with other tools. 

 

You can however improve performance by replacing UNION with UNION ALL.

PG

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 3 replies
  • 879 views
  • 0 likes
  • 3 in conversation