BookmarkSubscribeRSS Feed
Vijay77
Fluorite | Level 6

PROC SQL;
CREATE TABLE SL_1 AS
SELECT distinct A,AEC,'Patients ' AS VARIABLE, 1 AS GRP, COUNT(DISTINCT SUBJID) AS CNT
FROM A(WHERE=(FL='Y')) GROUP BY AEC
UNION ALL
SELECT distinct A,AEC,'Patients 2' AS VARIABLE, 2 AS GRP, COUNT(DISTINCT SUBJID) AS CNT
FROM A(WHERE=(FL='Y' AND FFL='N')) GROUP BY AEC
;quit;

 

How to write above code in Data step

3 REPLIES 3
Tom
Super User Tom
Super User

In general you wouldn't combine those types of calculations with the step that combines the datasets into one data step.

To combine two datasets (aka UNION) just use the SET statement.

data want;
  set have1 have2;
run;
yliu1234
Obsidian | Level 7

What if I have three tables that want to union?

Reeza
Super User
These are not three tables, it's one table with different summaries according to your posted code. Show the code for the three tables please. I suspect this could be simplified into 2 queries but need to see the full process.

DISTINCT isn't one that's great in SAS unless you have sorted data already, which may still be doable in a single data step.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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