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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 7655 views
  • 0 likes
  • 4 in conversation