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
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.