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

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;

 Capture.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

9 REPLIES 9
Reeza
Super User
This includes your actual data, did you intend to include that?
Wub_SAS
Obsidian | Level 7
Thank you @Reeza. No, I picked the wrong dataset. I contacted asked to get help for this post to be deleted so that can re-post with the correct sample dataset.
Reeza
Super User
I've deleted your code/data. You can feel free to edit your posts yourself, click the three lines beside the post and edit.
Wub_SAS
Obsidian | Level 7
Thank you for the help! @Reeza.
ChrisHemedinger
Community Manager
Posters can edit their own posts for a short time, after which they need to ask for moderator help. This helps to keep the integrity of the question after others reply.
Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
Wub_SAS
Obsidian | Level 7
Ok, thank you for the note @ChrisHemedinger; that will be helpful for future posts.
ballardw
Super User

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.

Wub_SAS
Obsidian | Level 7
Thanks a lot! That was very helpful.
Tom
Super User Tom
Super User

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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 9 replies
  • 3098 views
  • 5 likes
  • 5 in conversation