BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kairali
Calcite | Level 5

Hello,

I am new to SAS Programming and using SAS 9.4. Can someone help me understand the below error and the logic?

 

I have Startdate (D) mentioned as in following pattern (partial dates)

01:unk:2010:12:null:null 

I have run the attached code which displays a note

'Invalid numeric data ':' at line 141 column 21'

and

'Invalid third argument to function SUBSTR at line 141 column 9'. IMG_20200925_200747.jpg

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Your error message:

'Invalid third argument to function SUBSTR at line 141 column 9'. 

 

Your code @ line 141 is:

substr(D, 1, ':') = '01';

But the SUBSTR function uses a different format:

SUBSTR(variableposition <, length>)=characters-to-replace

 

 I would suggest looking into TRANWRD instead of SUBSTR here which allows you a little more control of what replacing. 

It should be:

substr(d, 1, 2) = '01'

For data validation for a field like this I'd break each component down into it's parts, evaluate it and then recombine them back into a date using DHMS or MDY() functions. 

 


@Kairali wrote:

Hello,

I am new to SAS Programming and using SAS 9.4. Can someone help me understand the below error and the logic?

 

I have Startdate (D) mentioned as in following pattern (partial dates)

01:unk:2010:12:null:null 

I have run the attached code which displays a note

'Invalid numeric data ':' at line 141 column 21'

and

'Invalid third argument to function SUBSTR at line 141 column 9'. IMG_20200925_200747.jpg


 

 

View solution in original post

3 REPLIES 3
Reeza
Super User

Your error message:

'Invalid third argument to function SUBSTR at line 141 column 9'. 

 

Your code @ line 141 is:

substr(D, 1, ':') = '01';

But the SUBSTR function uses a different format:

SUBSTR(variableposition <, length>)=characters-to-replace

 

 I would suggest looking into TRANWRD instead of SUBSTR here which allows you a little more control of what replacing. 

It should be:

substr(d, 1, 2) = '01'

For data validation for a field like this I'd break each component down into it's parts, evaluate it and then recombine them back into a date using DHMS or MDY() functions. 

 


@Kairali wrote:

Hello,

I am new to SAS Programming and using SAS 9.4. Can someone help me understand the below error and the logic?

 

I have Startdate (D) mentioned as in following pattern (partial dates)

01:unk:2010:12:null:null 

I have run the attached code which displays a note

'Invalid numeric data ':' at line 141 column 21'

and

'Invalid third argument to function SUBSTR at line 141 column 9'. IMG_20200925_200747.jpg


 

 

Kairali
Calcite | Level 5
Thank you! I had missed that.
ballardw
Super User

When you want to show us a log please copy the text from the log and then on the forum open a box using the </> icon and paste the text.

It is much easier to copy/paste code and highlight or make corrections to the code.

 

 

One of the invalid data type messages is showing "invalid numeric data :"

In the SUBSTR function if there is a third parameter it is the length of a string : Substr(var, 1,3)  <= the 3 is the number of characters. So Substr(var,1,":") the colon is not a number, an expression returning a number or a string that could be converted to a number "3" would work though is poor practice.

 

 

 

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1242 views
  • 1 like
  • 3 in conversation