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'.
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(variable, position <, 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'.
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(variable, position <, 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'.
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.