Hi all,
The following code seems to work as expected but it loses the labels and formats that should be copied from the "updated." table. Can you suggest a method to retain these dataset attributes?
&dsName = name of the dataset being processed
&pt = subject identifier
%dsSQLcolumns = list of columns to be selected for the "except" statement.
%dsSEQk = additional columns to be added onto the final "except_" table but are not part of the "except" statement.
Please note that there is no primary key in the datasets that I can pick.
proc sql;
create table except_&dsname
as
select
%dsSQLcolumns(ds=&dsname) %dsSEQk(ds=&dsname)
from updated.&dsname
natural join
(select
%dsSQLcolumns(ds=&dsname)
from updated.&dsname
where usubjid="&pt"
except
select
%dsSQLcolumns(ds=&dsname)
from olddata.&dsname
where usubjid="&pt");
quit;
The problem is likely to be with the natural join. Run this little test :
data a(drop=b) b(drop=a);
do i = 1 to 5;
a = i*10;
b = i**2;
output;
end;
format a z10.2 b dollar6. i percent10.;
run;
proc sql;
create table c as
select i as i_in_c, a, b
from a natural join b;
select * from c;
create table d as
select a.i as i_in_d, a, b
from a natural join b;
select * from d;
quit;
Note that the only difference between table c and table d is the fact that the origin of variable i is explicit in the select statement creating table d. Even when both variables in the join have the same format, the natural join drops the format. The solution is thus to mention one of the table names for every column involved in the join.
PG
The problem is likely to be with the natural join. Run this little test :
data a(drop=b) b(drop=a);
do i = 1 to 5;
a = i*10;
b = i**2;
output;
end;
format a z10.2 b dollar6. i percent10.;
run;
proc sql;
create table c as
select i as i_in_c, a, b
from a natural join b;
select * from c;
create table d as
select a.i as i_in_d, a, b
from a natural join b;
select * from d;
quit;
Note that the only difference between table c and table d is the fact that the origin of variable i is explicit in the select statement creating table d. Even when both variables in the join have the same format, the natural join drops the format. The solution is thus to mention one of the table names for every column involved in the join.
PG
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.