DATA Step, Macro, Functions and more

Constraints Removed

Accepted Solution Solved
Reply
Regular Contributor
Posts: 181
Accepted Solution

Constraints Removed

I have added constraints into a table but it removes it when someone overwrites the table. Is there any way to prevent it?

 

 

DATA TEMP;
SET SASHELP.CLASS;
RUN;

PROC SQL;
ALTER TABLE TEMP
ADD CONSTRAINT NOT_NULL_WEIGHT NOT NULL(WEIGHT);
QUIT;

DATA TEMP;
SET TEMP;
IF AGE >=15 THEN WEIGHT = .;
RUN;

 


Accepted Solutions
Solution
‎06-06-2016 01:35 PM
Respected Advisor
Posts: 4,644

Re: Constraints Removed

Constraints are kept and respected if you stay within SQL. Try


proc sql;
update temp
set weight = .
where age >= 15;
quit;

 

 

PG

View solution in original post


All Replies
Solution
‎06-06-2016 01:35 PM
Respected Advisor
Posts: 4,644

Re: Constraints Removed

Constraints are kept and respected if you stay within SQL. Try


proc sql;
update temp
set weight = .
where age >= 15;
quit;

 

 

PG
Respected Advisor
Posts: 4,644

Re: Constraints Removed

Use MODIFY if you want to retain the constraint. But note that 


DATA TEMP;
modify TEMP;
IF AGE >=15 THEN WEIGHT = .;
RUN;

 

is not equivalent to the SQL UPDATE query above. There is no rollback with MODIFY.

PG
Super User
Posts: 9,671

Re: Constraints Removed

Add a password in this table to avoid to rewrite it .

 

 

 

DATA TEMP(pw=aw12);
SET SASHELP.CLASS;
RUN;

data temp;
 set sashelp.class;
run;
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 218 views
  • 2 likes
  • 3 in conversation