Hi, I need to import a csv data (sample observations and variables attached) to SAS. I am using the below code and imported the data but couldn't solve a few issues I am having:
1. SAS read many of the character variables as single length (screenshot of the out put attached) which I couldn't increase applying informat, attrib or length functions.
2. Although the dataset is created with all the above issues, I am still getting error message in the log saying: "ERROR: Import unsuccessful. See SAS Log for details."
proc import datafile="C:\Sample3.csv"
dbms=csv
out=Sample3;
getnames=yes;
run;
By default Proc Import only examines 20 rows of data to set properties. If a "column" doesn't have any values in the first 20 rows then SAS sets a width of 1 and makes the column character.
Use the GUESSINROWS statement to tell SAS how many rows to read to set properties.
proc import datafile="C:\Sample3.csv" dbms=csv out=Sample3; getnames=yes; guessingrows=max; run;
Better if you have a an actual description of the file contents is to use that information to write a data step.
Import will attempt to treat a field with all digits as a numeric value which means that significant leading zeroes, such as appear in account information in many sources, get discarded. When Proc Import "reads" different data files that should have the same properties you can get different lengths and sometimes variable types which leads to problems when combining data sets.
By default Proc Import only examines 20 rows of data to set properties. If a "column" doesn't have any values in the first 20 rows then SAS sets a width of 1 and makes the column character.
Use the GUESSINROWS statement to tell SAS how many rows to read to set properties.
proc import datafile="C:\Sample3.csv" dbms=csv out=Sample3; getnames=yes; guessingrows=max; run;
Better if you have a an actual description of the file contents is to use that information to write a data step.
Import will attempt to treat a field with all digits as a numeric value which means that significant leading zeroes, such as appear in account information in many sources, get discarded. When Proc Import "reads" different data files that should have the same properties you can get different lengths and sometimes variable types which leads to problems when combining data sets.
Make to to tell SAS to check the WHOLE file before determining the type/length to GUESS for the variables.
Add this statement to the PROC IMPORT step.
guessingrows=max;
For your data step you are telling SAS to use COMMA as the delimiter.
data WORK.SAMPLE3;
infile datalines dsd truncover;
But your in-line data lines do NOT have commas as the delimiter.
In fact they don't appear to have any delimiter. If the delimiter is a TAB then DO NOT use in-line data. Normal SAS will replace the tabs with spaces when you submit the code. Or is the data in fixed column locations instead? In that case you need to use a different style of INPUT statement.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.