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;
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
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.
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
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 25. Read more here about why you should contribute and what is in it for you!
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.