Help using Base SAS procedures

import CSV file

Reply
Occasional Contributor
Posts: 10

import CSV file

[ Edited ]

I'm trying to import a large CSV file into SAS. When I imported, I found that some variables were not imported properly. For example, there is a variable, which is a number. The range is [0, 1], i.e., the value is 0.0004. When I imported, it becomes a dummy variable, either 0 or 1. What can I do to get the original value??? Thanks in advance!

 

PROC IMPORT OUT= WANTED
DATAFILE= "HAVE.csv"
DBMS=CSV REPLACE;
GETNAMES=YES;
DATAROW=2;
RUN;

Respected Advisor
Posts: 3,799

Re: import CSV file

Posted in reply to OceanDream

OceanDream wrote:

I'm trying to import a large CSV file into SAS. When I imported, I found that some variables were not imported properly. For example, there is a variable, which is a number. The range is [0, 1], i.e., the value is 0.0004. When I imported, it becomes a dummy variable, either 0 or 1. What can I do to get the original value??? Thanks in advance!


Show the data.  Show the code.

Super User
Posts: 11,343

Re: import CSV file

Posted in reply to data_null__

Look at several things. First is the CSV file and preferrably not using a spreadsheet program as most of those will make lots of assumptions about the data. Verify that the data is indeed 0.0004 or whatever.

 

Second is to add and supply a large value for guessingrows. By default SAS only examines a few rows to "guess" what the contents of a column may be. The first rows may have not been sufficient to note your decimals.

PROC IMPORT OUT= WANTED
DATAFILE= "HAVE.csv"
DBMS=CSV REPLACE;

Guessingrows = 32000;
GETNAMES=YES;
DATAROW=2;
RUN;

 

Third, look at the datastep code generated by proc import. It will tell you exactly what informat and format were assigned. You can copy the code and paste it into the editor and modify to make any desired changes such as changing informat or format, add labels and possibly get more useful variable names.

Occasional Contributor
Posts: 10

Re: import CSV file

ballardw, thank you very much! After I added "Guessingrows = 32000;", it works very well. you are right that SAS only uses a few rows to guess. And since my dataset has a lot of missing values, SAS just assumed it's a dummy variable. 

Super User
Posts: 19,851

Re: import CSV file

Posted in reply to OceanDream

@OceanDream Please mark the question answered if you have a solution. 

Ask a Question
Discussion stats
  • 4 replies
  • 403 views
  • 1 like
  • 4 in conversation