BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Mikeyjh
Calcite | Level 5

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;

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

PG

View solution in original post

1 REPLY 1
PGStats
Opal | Level 21

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

PG

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 993 views
  • 0 likes
  • 2 in conversation