05-27-2016 10:08 AM
I want to delete the last record if certain conditions apply. However, I am getting the following error:
ERROR 68-185: The function CONTAINS is unknown, or cannot be accessed.
Here is what I am working on:
data test; format date date9.; input sn $ date ctry $ source $; datalines; 1 20000 US PL 1 20001 US PL 1 20005 US CIM /*this would be removed*/ 2 20000 CA SOS 2 25000 FR CIM /*this would be kept*/ ; run; proc sort data = test; by sn date ctry; run; data test2; set test; by sn; if last.ctry = lag1(last.ctry) and (abs(last.date - lag1(last.date) < 180) and source contains ('CIM') then delete; run;
05-27-2016 10:26 AM
Simple SAS does not have a datastep condition CONTAINS though it is availabe in Proc SQL. There are a number of other methods. I would likely use
... and index(source,'CIM') > 0 then
If source might actual have lower case versions such as "cim" "Cim" "CiM" that you want to match as well then use
index( Upcase(source),'CIM') >0
05-27-2016 10:28 AM
You will have read the documentation yes?
Contains only works on where clauses, you want:
and index(source,"CIM") > 0 then...
05-27-2016 12:31 PM - edited 05-27-2016 12:52 PM
Also, what do you expect LAST.CTRY and LAST.DATE to contain, given that neither CTRY nor DATE appears in the BY statement (cf. section "Processing BY Groups" in the documentation)?
Side note: It's interesting to see that FIRST.xxx and LAST.xxx variables with arbitrary names xxx can be freely used as temporary (i.e. automatically dropped) variables which are automatically retained and initialized to zero (not as index variables of DO loops, though). Fun example:
data test; set sashelp.class end=eof; first.xy=sqrt(first.xy+1); last.abc=1/(last.abc+1); if eof then put first.xy= / last.abc= ; run;