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

Hi, 

 

I would like to know how to use the data_null_to have a look at the first few lines of a external file.

I know I should use option obs and statement List, but I have no idea how to let sas read the file by using data_null.

 

 

Regards

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Your file isn't showing delimiters that I can see, my guess is it's tab delimited?

How will American Samoa be read in because of the spaces? I suspect that's causing your issues. 

 

When you're reading in a file to see the format you should not specify the variables in the INPUT statement. When you do that you're already making assumptions on the data which could be incorrect. 

You want to see the actual values so a plain INPUT statement is what you need. Modify your code as following and see if it works for you:

 

data _null_;
infile world obs=10;
input;
list;
run;

@YangYY wrote:

Thank you for your rely and it is helpful!

But I've found another problem after trying this.

I was asked to use data_null_and OBS and LIST to have a look at the first few lines of the given file.

 

My code is 

data _null_;
infile world obs=10;
input continent $1-20 abbreviation $21-29 country_name $30-50;
list;
run;

 

The log shows as picture 1 and it is different from the first few lines of the given file.

 

The given file is also been uploaded.

 

 

 


 

View solution in original post

6 REPLIES 6
Kurt_Bremser
Super User

You can do this:

data _null_;
infile "insert full path here";
input;
put _infile_;
if _n_ = 5 then stop;
run;

But I find it much better to use a proper text editor (eg notepad++) to inspect files.

YangYY
Quartz | Level 8

Thank you for your rely and it is helpful!

But I've found another problem after trying this.

I was asked to use data_null_and OBS and LIST to have a look at the first few lines of the given file.

 

My code is 

data _null_;
infile world obs=10;
input continent $1-20 abbreviation $21-29 country_name $30-50;
list;
run;

 

The log shows as picture 1 and it is different from the first few lines of the given file.

 

The given file is also been uploaded.

 

 

 

YangYY
Quartz | Level 8

My log shows as

 
 
 
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
2 Europe AL Albania 36
4 Australia AS American Samoa 43
6 Africa AO Angola 35
8 Antarctica AQ Antarctica 39
10 South America AR Argentina 38
NOTE: 10 records were read from the infile WORLD.
The minimum record length was 35.
The maximum record length was 48.
 
 
and the files shows as
South America BO Bolivia
North America BQ Bonaire, Sint Eustatius and Saba
Europe BA Bosnia and Herzegovina
Africa BW Botswana
Antarctica BV Bouvet Island
South America BR Brazil
Asia IO British Indian Ocean Territory
Asia BN Brunei
Europe BG Bulgaria
Africa BF Burkina Faso
Africa BI Burundi
Asia KH Cambodia
Africa CM Cameroon
Africa CM_NG Cameroon/Nigeria
North America CA Canada
Africa CV Cape Verde
North America KY Cayman Islands
Africa CF Central African Republic
Africa TD Chad
South America CL Chile
Asia CN China
Asia CN_IN China/India
Asia CN_TW China/Taiwan_POC
Asia CN_VN China/Viet_Nam
Asia CX Christmas Island
 
 
 
Thank you so much for your help
Kurt_Bremser
Super User

Do not post infile data in the main posting window, use the {i} button for this. This is necessary to keep horizontal positioning and special characters (eg tabs) as is.

And once again, it is much easier to view the text file with a good editor to see what it contains. Such editors have options to view the hex codes, which help greatly in determining what is used for delimiters etc.

Reeza
Super User

Your file isn't showing delimiters that I can see, my guess is it's tab delimited?

How will American Samoa be read in because of the spaces? I suspect that's causing your issues. 

 

When you're reading in a file to see the format you should not specify the variables in the INPUT statement. When you do that you're already making assumptions on the data which could be incorrect. 

You want to see the actual values so a plain INPUT statement is what you need. Modify your code as following and see if it works for you:

 

data _null_;
infile world obs=10;
input;
list;
run;

@YangYY wrote:

Thank you for your rely and it is helpful!

But I've found another problem after trying this.

I was asked to use data_null_and OBS and LIST to have a look at the first few lines of the given file.

 

My code is 

data _null_;
infile world obs=10;
input continent $1-20 abbreviation $21-29 country_name $30-50;
list;
run;

 

The log shows as picture 1 and it is different from the first few lines of the given file.

 

The given file is also been uploaded.

 

 

 


 

YangYY
Quartz | Level 8
Thank you so much!!!
My problems got solved!!

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