BookmarkSubscribeRSS Feed
LB
Quartz | Level 8 LB
Quartz | Level 8

Hello all-

I have a file that is marked by standard delimiters in a csv file.

namely "a","b","c" etc etc.  The problem is when I import, it converts some of the variables into dates (which they are numbers) and almost everything else becomes variables with character values (where some are and others not).

I can't share any examples as its all HIPAA. Just looking for reasons/solutions.

I don't want to do  with infile as some of the files are not all the same and there are 280 variables.

Thanks

Lawrence

2 REPLIES 2
Doc_Duke
Rhodochrosite | Level 12

The first thing to do is to set the GUESSINGROWS statement to some large number.

http://support.sas.com/documentation/cdl/en/proc/65145/HTML/default/viewer.htm#p13kvtl8ezj13in17i6m9...

That may fix it.

Doc Muhlbaier

Duke

ballardw
Super User

By any chance did you open the CSV file in Excel and then save it? Excel is known to covert text values such as 5-10 in csv to dates without warning.

SAS is likely to treat values such as 9/10/2012 or 9-10-2012 as a date but if there is no punctuation associated 9102012 it won't usually be treated as a date.

When importing CSV the GUESSINGROWS option controls how many rows of data to examine to determine variable type. The default is 20 rows. If your data has just about any character other than . in the first 20 rows for any variable SAS by default will assign it as character. If some character fields have nothing but digits in first 20 then they become numeric. This at least can be solved by using GUESSINGROWS= 32767.

Another issue you may have is numeric coded values with leading zeros may have been treated as numeric and the leading zeros are gone.

Since the data step to read the file is generated when running PROC IMPORT you may find it helpful to either RECALL (F4) the code or copy and edit from the log changing informats and the input statment to desired types.

You could post a couple examples of the values being treated as dates.

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