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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 8833 views
  • 0 likes
  • 4 in conversation