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

Suppose an easy data set as follows.

data _;
input i @@;
cards;
1 2 3 4 5 6 7 8 9 10
;
run;

Using SET, one can create a new indicator variable as follows.

data _;
set _;
o=mod(i,2);
run;

This can be similarly done through SQL as follows, but it spits out a warning message—WARNING: This CREATE TABLE statement recursively references the target table. A consequence of this is a possible data integrity problem.

proc sql;
create table _ as
select *,mod(i,2)=0 as e
from _;
quit;

Is there any correct alternative?

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

Or to avoid processing the table twice:

 

proc sql;
  create table _TMP_TABLE_ as
  select *, mod(I,2)=0 as E
  from _;
quit;
proc datasets noprint;
  age _TMP_TABLE_ _;
quit;

 

 

 

 

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

To avoid problems, this operation must be done in two steps in SQL:

 

proc sql;
alter table _ add o real;
update _ set o = mod(i,2);
quit;
PG
ChrisNZ
Tourmaline | Level 20

Or to avoid processing the table twice:

 

proc sql;
  create table _TMP_TABLE_ as
  select *, mod(I,2)=0 as E
  from _;
quit;
proc datasets noprint;
  age _TMP_TABLE_ _;
quit;

 

 

 

 

AI Navigator GIF.gif


Navigate AI governance with SAS tools for compliance and ethical AI practices. Try SAS Ai Navigator for free for the first six months.

Check it out on Microsoft Marketplace →

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 4013 views
  • 0 likes
  • 3 in conversation