BookmarkSubscribeRSS Feed
Elfakhfakh
Fluorite | Level 6

Hello all, 

 

I am new to SAS and I am using SAS university edition and I am trying to set integrity constraints to an existing data set that has one observation violates one of the constraints. But the code does not complete because of this error ( ERROR: Integrity constraint Low_ck was rejected because 1 observations failed the constraint. ) please find the code below. 

 

My goal from this code is to make sure that the data set meets all the constraints and if not, a way or a report identifying which observations don't meet them and which one. I can do it but I have to create an empty data set and append this data set to it then I can get the report by the audit file, can I do it without the empty data set method? 

 

proc datasets library=pg1 nolist;
modify NYSE_test;
ic create Symbol_pk = primary key(Symbol)
message = "Symbol must be unique and non-missing"
msgtype = user;

ic create Open_ck = check(where=(Open is not missing))
message = "Open price must not missing"
msgtype = user;

ic create Close_ck = check(where=( Close between Low and High ))
message = "Close price must not missing or not between L and H"
msgtype = user;

ic create Low_ck = check(where=(Low is not missing))
message = "Low price must not missing"
msgtype = user;

ic create High_ck = check(where=(High is not missing))
message = "High price must not missing"
msgtype = user;

run;

audit NYSE_test;
initiate;
run;
quit;

title "Integrity Constraint Violations";
proc report data=pg1.NYSE_test(type=audit);
where _ATOPCODE_ in ('EA' 'ED' 'EU');
columns Symbol Date Open Low High Close Volume _ATMESSAGE_;
define  _atmessage_ / display "_Error Report_"
width=30 flow;
run;

thank you so much in advance, 

 

Mohamed Elfakhfakh 

1 REPLY 1
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

you have to fix the record that doesn't meet you constrants.

ic create Low_ck = check(where=(Low is not missing))
message = "Low price must not missing"
msgtype = user;

you data has 1 record with missing low price.

 

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 1 reply
  • 756 views
  • 0 likes
  • 2 in conversation