BookmarkSubscribeRSS Feed
takumamih
Calcite | Level 5
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
3 REPLIES 3
ballardw
Super User

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.

Reeza
Super User

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

Kurt_Bremser
Super User

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.

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!

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.

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