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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 902 views
  • 2 likes
  • 5 in conversation