BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ChickenLittle
Obsidian | Level 7

I have an excel file that I saved down as a CSV file. When I run the Proc Import code, it converts one of my fields that is in a text format in the excel/CSV file into a numeric format in the sas data set. Is there a way to import the data and keep the numbers in a character format?

 

proc import datafile="librarypath/Sample_List.csv"

out=LibraryName.Sample_List

dbms=csv

replace;

getnames=YES; 

run;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Can you provide some details, such as the actual CSV file and indicate which column?

Proc IMPORT guesses as to variable types. So if something looks like a number, such as 123454678, SAS will guess that it should be numeric.

If you have other values in that column further down that are obviously not numbers because they contain non-digit characters you can try adding GUESSINGROWS=MAX; to your proc import code.

 

OR look at the data step generated to read the file that appears in the LOG. Copy the text from the LOG into the editor and change the properties of the INFORMAT and FORMAT lines associated with that column as needed. Numeric will likely appear as BEST32. in the INFORMAT. Change that to $16. (or however many characters you need).

 

If you read the documentation on Proc Import you will find that the procedure examines very few rows before making guesses as to variable types by default, hence the option GUESSINGROWS to allow you to extend that.

 

Or just write a data step based on the description you should have of the file.

That way all the files read with the same data step have the same properties and variable names don't change, variable types don't change, variable lengths don't change based on different source files. (Which will happen with Proc Import)

View solution in original post

1 REPLY 1
ballardw
Super User

Can you provide some details, such as the actual CSV file and indicate which column?

Proc IMPORT guesses as to variable types. So if something looks like a number, such as 123454678, SAS will guess that it should be numeric.

If you have other values in that column further down that are obviously not numbers because they contain non-digit characters you can try adding GUESSINGROWS=MAX; to your proc import code.

 

OR look at the data step generated to read the file that appears in the LOG. Copy the text from the LOG into the editor and change the properties of the INFORMAT and FORMAT lines associated with that column as needed. Numeric will likely appear as BEST32. in the INFORMAT. Change that to $16. (or however many characters you need).

 

If you read the documentation on Proc Import you will find that the procedure examines very few rows before making guesses as to variable types by default, hence the option GUESSINGROWS to allow you to extend that.

 

Or just write a data step based on the description you should have of the file.

That way all the files read with the same data step have the same properties and variable names don't change, variable types don't change, variable lengths don't change based on different source files. (Which will happen with Proc Import)

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1 reply
  • 344 views
  • 1 like
  • 2 in conversation