DATA Step, Macro, Functions and more

what is the difference between If and Where statment.b

Reply
Frequent Contributor
Frequent Contributor
Posts: 81

what is the difference between If and Where statment.b

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
SAS Super FREQ
Posts: 8,745

Re: what is the difference between If and Where statment.b

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
N/A
Posts: 0

Re: what is the difference between If and Where statment.b

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.
Frequent Contributor
Posts: 139

Re: what is the difference between If and Where statment.b

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
Ask a Question
Discussion stats
  • 3 replies
  • 114 views
  • 0 likes
  • 4 in conversation