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;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.