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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Doc_Duke
Rhodochrosite | Level 12

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).

View solution in original post

7 REPLIES 7
Doc_Duke
Rhodochrosite | Level 12

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.

Haikuo
Onyx | Level 15

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

JohnPura
Calcite | Level 5

@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.

Doc_Duke
Rhodochrosite | Level 12

here is the documentation for the format:

SAS(R) 9.3 Formats and Informats: Reference

JohnPura
Calcite | Level 5

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.

Doc_Duke
Rhodochrosite | Level 12

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).

JohnPura
Calcite | Level 5

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 7 replies
  • 4215 views
  • 0 likes
  • 3 in conversation