BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

When I put the following logic

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

I got the following messge

INVALID THIRD ARGUMENT TO FUNCTION SUBSTR AT LINE 302 COLUMN 3.

When I put
WHERE SUBSTR(TRIM(LEFT(BRPROV)),1,7) = 'ALBERTA' OR
(SUBSTR(TRIM(LEFT(BRPROV)),1,12) = 'SASKATCHEWAN'

I don't get any error message.

Can any one please explain to me Why such error message comming?


Thanks

Inpda
1 REPLY 1
Cynthia_sas
SAS Super FREQ
Hi:
I can't duplicate your error message. When I run this code:
[pre]
data testfile;
length BRPROV $15;
infile datalines;
input BRPROV $;
return;
datalines;
ALBERTA
SASKATCHEWAN
SASKATOON
MANITOBA
;
run;

data ifstmt;
set testfile;
IF SUBSTR(TRIM(LEFT(BRPROV)),1,7) = 'ALBERTA' OR
(SUBSTR(TRIM(LEFT(BRPROV)),1,12) = 'SASKATCHEWAN';
run;
[/pre]

I get a different error message from the mismatched parentheses in the second SUBSTR function. You have 3 open parens and 3 close parens in the test for ALBERTA, but you have 4 open parens and only 3 close parens in the test for SASKATCHEWAN.
[pre]
1386 data ifstmt;
1387 set testfile;
1388 IF SUBSTR(TRIM(LEFT(BRPROV)),1,7) = 'ALBERTA' OR
1389 (SUBSTR(TRIM(LEFT(BRPROV)),1,12) = 'SASKATCHEWAN';
-
79
ERROR 79-322: Expecting a ).

1390 run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.IFSTMT may be incomplete. When this step was stopped there were 0 observations and 1
variables.
WARNING: Data set WORK.IFSTMT was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds

[/pre]

And, when I run a PROC PRINT with a WHERE statement, I get the SAME error message about the mismatched parens.
[pre]
1395
1396 proc print data=testfile;
1397 WHERE SUBSTR(TRIM(LEFT(BRPROV)),1,7) = 'ALBERTA' OR
1398 (SUBSTR(TRIM(LEFT(BRPROV)),1,12) = 'SASKATCHEWAN' ;
-
79
ERROR 79-322: Expecting a ).
1399 title 'using WHERE statement';
ERROR: Syntax error while parsing WHERE clause.
1400 run;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds


[/pre]

Rather than just posting partial code snippets, you may be helped more by contacting Tech Support and showing them your complete code, your entire SAS log. They can probably help you figure out the problem in a more timely fashion.

cynthia

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
  • 1 reply
  • 673 views
  • 0 likes
  • 2 in conversation