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

sas-innovate-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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