I want to merge two datasets. I previously needed to sort them first, them
data want
set have1 have2
indsname=ind
contributing_tbl=ind;
run;
In this way, I get a new variable indicating where it is originally from
However, use "set" is too slow and needs to sort first, which takes more time, I want to change to use proc sql;
however, I need advice from you how to have a simiar statement that adds a column that indicting where it is orginally from have1, or have2,
would you please advice? Thanks.
As mentioned by @Doc_Duke, you are not sorting the data nor merging it. The set statement in the given example will take all the data from table1, then below that will set all the data from table2. You can use the proc append procedure to achieve the same thing (and it would be quicker):
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a000070936.htm
But if your fixed on SQL, you won't get much speed gains, you would use union command - note columns have to all be the same:
proc sql; create table WANT as select * from (select *,"From Table1" as INTBL from TABLE1) union all select * from (select *,"From Table2" as INTBL from TABLE2); quit;
The syntax you have is not technically correct (missing multiple semi-colons), so it is hard to understand what you are really trying to do. The DATA step, as stated, does not require the data sets to be sorted; is there a BY statement missing?
As mentioned by @Doc_Duke, you are not sorting the data nor merging it. The set statement in the given example will take all the data from table1, then below that will set all the data from table2. You can use the proc append procedure to achieve the same thing (and it would be quicker):
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a000070936.htm
But if your fixed on SQL, you won't get much speed gains, you would use union command - note columns have to all be the same:
proc sql; create table WANT as select * from (select *,"From Table1" as INTBL from TABLE1) union all select * from (select *,"From Table2" as INTBL from TABLE2); quit;
Thank you!
My actual problem is,
combine first two into class I; then combine the last two into class II; then combine these two classes into one big dataset;
can you give advice how to do it with one proc sql step?
Thanks
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.