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
Diamond | Level 26
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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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