BookmarkSubscribeRSS Feed
Inp
Obsidian | Level 7 Inp
Obsidian | Level 7
Hi
Here is my actual coding

299 DATA BUNDRPT REGULERT;
300 SET COMBINE;
301 IF (SUBSTR(TRIM(LEFT(BRPROV)),1,7) = 'ALBERTA') OR
302 (SUBSTR(TRIM(LEFT(BRPROV)),1,12) = 'SASKATCHEWAN' AND
303 PUT(CIDKEY,SASK.) = 'Y') THEN OUTPUT BUNDRPT;
304 ELSE OUTPUT REGULERT;
305 RUN;

Error messages

NOTE: INVALID THIRD ARGUMENT TO FUNCTION SUBSTR AT LINE 302 COLUMN 3.
CIDKEY=1111111111111111 ACCOUNT=000000111111111 ORIGDATE=04JUL2003 ISSUEDTE=04JUL2003 MATDATE=04JUL2008 BLTRANS=77777 BRPROV=ALBERTA
CUSTNM=xxxxxxxxxxxxx MKEY=vvvvvvvvvvv NAME=cccccccccc CADD1=eeeeeee CADD2=rrrrrrrrrr cccc MY T1A 7H3

IF I PUT WHERE STATMENT instead of IF, I don't get errory message.

What make the difference between if and where statment.

Note that field BRPROV is 18 characters length long
thanks
(from the proc contents I found the following
# Variable Type Len Pos Format Label
44 BRPROV CHAR 18 320
)

Anton Message was edited by: Inp
3 REPLIES 3
Cynthia_sas
SAS Super FREQ
Hi:
I note you still have the missing parentheses that I noted in my other forum posting on this subject:
http://support.sas.com/forums/thread.jspa?messageID=11428Ⲥ

This statement has [pre]
302 (SUBSTR(TRIM(LEFT(BRPROV)),1,12) = 'SASKATCHEWAN' AND
[/pre]

4 open parens and just 3 close parens. As I said in the previous post, I could not duplicate your error message.

cynthia
deleted_user
Not applicable
Don't use the TRIM function. What you are then returning when BRPROV = 'ALBERTA' is a 7 character value, which is ok for the first SUBSTR but not for the second SUBSTR; 12 is out of range for a 7 character value.
darrylovia
Quartz | Level 8
To add my 2 cents SAS has a "starts with" operator =:, So you don't need to coun t the number of positions in a substr function. For Example:

So you could change your if statement from


IF (SUBSTR(TRIM(LEFT(BRPROV)),1,7) = 'ALBERTA') OR
(SUBSTR(TRIM(LEFT(BRPROV)),1,12) = 'SASKATCHEWAN' AND


to if BRPROV=:''ALBERTA'' or
BRPROV=:''SASKATCHEWAN' ';


Of course ALBERTA and ALBERTAIWYRIAWREIOAW would both be picked up but you should be OK.
-Darryl

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 735 views
  • 0 likes
  • 4 in conversation