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

Proc import reading the delimited text file:

which has 100 rows and 10 variables

variable name First_Name

first 20 rows, the longest value of First_Name is 10 characters

In the delimited file, later rows has longest value of First_Name is 30 characters

 

Should I use length statement or guessingrows= option will work

 

I could not find in sas prep guide

 

thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

The GUESSINGROWS option will work for that single file.

 

But if you want to get consistent results across multiple potential versions of the same data then create a data step to read the delimited file directly instead of forcing SAS to guess how to define the variables based on the examples in the one version of the file it is currently looking at.

[Editors Note - Start]
As per the PROC IMPORT documentation.
The procedure scans the first 20 rows to count the variables, and it attempts to determine the correct informat and format for each variable.

You can adjust the number of rows scanned with the GUESSINGROWS Statement

By using PROC IMPORT you are letting the code determine the format of your data, and that can result in issues. For example say you have a column that contains 12032023. Is this the number 12,032,023, a date in December 12/03/2023, (MM/DD/YYYY), a date in March 12/03/2023 (DD/MM/YYYY), or something else?

As mentioned later in this post, you probably will want to take ownership of your code and control how to read the data, which you can do with the INPUT Statement.
[Editors Note - End]

View solution in original post

6 REPLIES 6
Tom
Super User Tom
Super User

The GUESSINGROWS option will work for that single file.

 

But if you want to get consistent results across multiple potential versions of the same data then create a data step to read the delimited file directly instead of forcing SAS to guess how to define the variables based on the examples in the one version of the file it is currently looking at.

[Editors Note - Start]
As per the PROC IMPORT documentation.
The procedure scans the first 20 rows to count the variables, and it attempts to determine the correct informat and format for each variable.

You can adjust the number of rows scanned with the GUESSINGROWS Statement

By using PROC IMPORT you are letting the code determine the format of your data, and that can result in issues. For example say you have a column that contains 12032023. Is this the number 12,032,023, a date in December 12/03/2023, (MM/DD/YYYY), a date in March 12/03/2023 (DD/MM/YYYY), or something else?

As mentioned later in this post, you probably will want to take ownership of your code and control how to read the data, which you can do with the INPUT Statement.
[Editors Note - End]

souji
Obsidian | Level 7

 

If I use GUESIINGROES=yes;

Then, it will read all value (30 character ) instead of up to 10 characters  for remaining variable right

souji
Obsidian | Level 7

Correcting**

GUESSINGROWS=yes;

ed_sas_member
Meteorite | Level 14

Hi @souji ,

 

you can specify a specific number to indicates the number of rows to scan in the input file to determine the appropriate data type and length of variables:

	guessingrows=30;

or you can simply put 'max', but it could affect performance, depending on the size of your dataset.

 

	guessingrows=max;

 

Kurt_Bremser
Super User

To take control of the import process, take the guessing of proc import out of it. Copy the data step (that proc import created) from the log, and adapt it to your column lengths as documented for the delimited file. By studying this data step (and making use of the documentation), you will be able to do a lot of optimization by omitting unnecessary statements or part of statements.

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
  • 6 replies
  • 34027 views
  • 3 likes
  • 4 in conversation