BookmarkSubscribeRSS Feed
dwsmith
Obsidian | Level 7

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;
4 REPLIES 4
ballardw
Super User

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

You will have read the documentation yes?

http://support.sas.com/kb/43/303.html

 

Contains only works on where clauses, you want:

and index(source,"CIM") > 0 then...

FreelanceReinh
Jade | Level 19

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;
PGStats
Opal | Level 21

@FreelanceReinh, interesting, but harmful knowledge. I hope I will never have to look at such coding!

PG

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 1171 views
  • 2 likes
  • 5 in conversation