DATA Step, Macro, Functions and more

Date and time not in proper format

New Contributor
Posts: 3

Date and time not in proper format

My date/time in the raw data file is in a mmddyyyy 00:00 format as a single variable, and I cannot get it to show up properly in sas.
Several informats gave me missing values, correct dates with no time, 1960/01/01 dates, etc.
Also, the field has about 20 characters, but it only shows up if I tell sas that it's 30 characters or more. 
Every time the next variable in the row is missing (PM25), the date/time is also missing. 
154  data burnaby1;
155      set burnaby;
159      input @4 testchar $1. @;
160      drop testchar;
161      if testchar in ('0','1','2','3','4','5','6','7','8','9') then
162          do;
163              input   @3  dattim :anydtdtm30.
164                      PM25 32-38
165                      NO2 43-49;
167              output;
168          end;
169      format dattim datetime20.;
170  run;
Base SAS 9.3 TS1M2
Super User
Posts: 10,483

Re: Date and time not in proper format

First try the anydtdtm with a 32 width. Sometimes using the full width allowed works better, or don't specify one at all.


What file format is your raw data file? Since you are showing code for a data set already in existence you may want to back up a step.

If you start with Excel and are using Proc import you might try saving the data as CSV before attempting to import it. Use a largish value for a guessingrows parameter.

Super User
Posts: 17,780

Re: Date and time not in proper format

Your code is nice, but without an example of the data we can't say much. 

Super User
Posts: 6,928

Re: Date and time not in proper format

Your code does not make sense. If you already have a dataset, you need no input statement, as the set statement does the read.

If you want to read from an external file, you have to use an infile statement to open the file for INPUTting.


Post an example of your raw data file, as a properly created data step will very probably fix your problems in one sweep.

Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 3 replies
  • 4 in conversation