Hi,all.
Is there any way of making a variable for catch "original dataset" after union statement when proc sql.
Though value which exisit both dataset is replaced to final dataset.
("value which exisit both dataset" is "paper2 b1" in the below example.)
For example
data Dataset1;
input A$ B$ ;
cards;
paper1 a1
paper2 b1
paper2 b1
;
run;
data Dataset2;
input A$ C$;
cards;
paper2 b1
paper3 c1
;
run;
proc sql;
create table Dataset3 as
select * from Dataset1
union
select * from Dataset2;
quit;
Image of "Dataset3"
I want to get the result like below,in short,variable "XX" have the value of the observation's mother or parent dataset.
Any value is ok(character or number) if we can grasp the diffenrence of parent dataset.
Image of my hoping.
Thank you in advance.
If you insist on using SQL UNION. Please note that unless you specify UNION CORRESPONDING, variables from both tables are matched simply on their position in the variable list. In your example, B is matched with C.
I suggest to try:
proc sql;
create table Dataset3 as
select "Dataset1" as source, A, B from Dataset1
union corr
select "Dataset2" as source, A, C as B from Dataset2;
quit;
Use a data step?
data want;
Set a b indsname=source;
Dset=source;
Run;
Hi,Reeza
Thank you for your helping.
Actually I insist on using proc sql,but your information is useful.
Because I never hard "indsname".I'll use it soon.Thanks.
If you insist on using SQL UNION. Please note that unless you specify UNION CORRESPONDING, variables from both tables are matched simply on their position in the variable list. In your example, B is matched with C.
I suggest to try:
proc sql;
create table Dataset3 as
select "Dataset1" as source, A, B from Dataset1
union corr
select "Dataset2" as source, A, C as B from Dataset2;
quit;
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!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: