BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Rahul_SAS
Quartz | Level 8

Hi Experts,

 

I am appending 4 tables with same variable names using SQL UNION and SET statement in datastep but its not giving me all the employee_names its missing few employees.

What  i need is, getting all the records (for employee_name, sponsor, projectcode and employee_region) from all 4 tables.

 

please help me to resolve the issue and correct me if i missed something.

 

proc sql noprint;
create table TEMP as
select  employee_name, sponsor, projectcode, employee_region from table1
union all
select  employee_name, sponsor, projectcode, employee_region from table2

union all

select  employee_name, sponsor, projectcode, employee_region from table3

union all

select  employee_name, sponsor, projectcode, employee_region from table4t;

quit;

 

 

data test (keep= employee_name sponsor projectcode employee_region);
set table1 table2 table3 table4;
run;

 

data test (keep= employee_name sponsor projectcode employee_region);

set table1

set table2

set table3

set table4;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

I would expect this

data test (keep= employee_name sponsor projectcode employee_region);

set table1 

set table2 

set table3 

set table4;
run;

to have multiple errors about data set SET not found, unless you have created a data set named SET previously. In which case it would have been included 3 times

 

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

No test data, can't do anything.  As for your question are all three methods returning the same amount of observations which is implied with "using SQL UNION and SET statement in datastep but its not giving me all the employee_names its missing few employees.".  If so then you have what you should expect from the set, each of the datasets appended together which is what this does:

data test (keep= employee_name sponsor projectcode employee_region);
set table1
    table2
    table3
    table4;
run;

Do note however that you should only have one set statement followed by the datasets followed by a semicolon, otherwise you will get an error.

ballardw
Super User

I would expect this

data test (keep= employee_name sponsor projectcode employee_region);

set table1 

set table2 

set table3 

set table4;
run;

to have multiple errors about data set SET not found, unless you have created a data set named SET previously. In which case it would have been included 3 times

 

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

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