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

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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