Hi all,
I have the following code:
data temp3;
set temp2;
format _date date9.;
_date = mdy(scan(date,1,'/'),scan(date,2,'/'),scan(date,3,'/'));
run;
The weird thing is that _date exists for some values, but for other values I get the following errors:
NOTE: Character values have been converted to numeric values at the places given by:
(Line):(Column).
1735:17 1735:48 1735:79
NOTE: Invalid numeric data, '.6' , at line 1735 column 17.
Patient_ID=487 date=
6/10/2004 _date=. _ERROR_=1 _N_=8
NOTE: Invalid numeric data, '.9' , at line 1735 column 17.
Patient_ID=487 date=
9/10/2004 _date=. _ERROR_=1 _N_=9
NOTE: Invalid numeric data, '.10' , at line 1735 column 17.
Patient_ID=491 date=
10/01/2004 _date=. _ERROR_=1 _N_=11
NOTE: Invalid numeric data, '.4' , at line 1735 column 17.
Patient_ID=492 date=
4/24/2007 _date=. _ERROR_=1 _N_=15
NOTE: Invalid numeric data, '.4' , at line 1735 column 17.
Where are these periods (e.g. '.6') before the number coming from? I've tried to compress them out, but I get the same error.
The weird thing is that the formatting for all the dates are the same, so I don't see why it should work for some, but not all.
Thanks!
try this:
data temp3;
set temp2;
FORMAT date $hex20.;
PUT date;
run;
you just want to see what the incoming data look like. Once you print it, you can look up the codes on the web (they are different depending on your server platform).
you have some junk in the date character string. use the $HEXw. format to see just what it is. I suspect a <CR> or <LF> as the printout goes to a new line before printing the date.
I don't have an answer for your question, but seems to me using informat would be a more straightforward option:
_date=input(date,ANYDTDTE10.);
Haikuo
@Doc@Duke - SAS doesn't seem to recognize that format.
@haikou - The errors disappeared, but I'm still having the issue that certain dates are not being correctly formatted to a SAS date.
here is the documentation for the format:
My code looks something like this now:
data temp3;
set temp2;
format _date $ hex10.;
_date = input(date,$hex10.);
run;
When running it, ALL the _date values are now invalid arguments to the input function, with a default value of 2020202020.
try this:
data temp3;
set temp2;
FORMAT date $hex20.;
PUT date;
run;
you just want to see what the incoming data look like. Once you print it, you can look up the codes on the web (they are different depending on your server platform).
Thank you so much! I ran it and got '0A'x (LF) as the leading character for the problematic values. compress(date,'0A'x) did the trick.
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.