BookmarkSubscribeRSS Feed
d6k5d3
Pyrite | Level 9

I am wondering why SAS would read TIME as numeric in one dataset and character in another. I used PROC IMPORT to open the datasets. The datasets were exported by SAS, and while exporting TIME was formatted as "time.20.". I even tried guessingrows= max. But no help!

 

What causes SAS to do so? Any way to get rid of that? I have around 60 variables. Is copying the code from log and fixing where needed the only option?

 

Much thanks.

 

Regards.

3 REPLIES 3
Reeza
Super User

@d6k5d3 wrote:

I am wondering why SAS would read TIME as numeric in one dataset and character in another. I used PROC IMPORT to open the datasets. The datasets were exported by SAS, and while exporting TIME was formatted as "time.20.". I even tried guessingrows= max. But no help!

What causes SAS to do so? Any way to get rid of that?

 

You're using a guessing proc, it makes the best guess it can. My guess is there's something in one that it can't read so it sets the column to be a character instead. A lot of blanks or if there's a character in a row can cause this. 

 


@d6k5d3 wrote:

I have around 60 variables. Is copying the code from log and fixing where needed the only option?

 

 



60 variables isn't actually that much, copying the code from the log and fixing it is your best bet. You only need to do it once, if you know the data sets are identical. Take that program and copy/paste it and change the file path for the second. You can hold down ALT+SHIFT while highlighting to avoid copying the line numbers. Or ALT+CTRL, don't remember exactly but one of those works. 

 

 

d6k5d3
Pyrite | Level 9
Yes, holding the ALT key while selecting with mouse to my rescue.
Tom
Super User Tom
Super User

 I have around 60 variables. Is copying the code from log and fixing where needed the only option?

I usually find that just copying the header line from the file and converting it to a LENGTH statement is about all I need to do to read a delimited file.  You can probably do a better job of guessing what type to use for each variable from the header than PROC IMPORT can from the data.

data want ;
  length firstvar $10 var2 8 var3 8 .... lastvar 8 ;
  infile 'myfile.csv' dsd truncover firstobs=2;
  input firstvar -- lastvar;
run;

 Add FORMAT and/or INFORMAT statement for any variables that NEED them. Most will NOT need either as SAS already knows how to read and write both numbers and character strings.  DATE, TIME and DATETIME fields are usually the only ones that need to have formats and/or informats attached.

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 679 views
  • 1 like
  • 3 in conversation