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;
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)
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)
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.
Ready to level-up your skills? Choose your own adventure.