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
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.
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.
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.
My log shows as
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.
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.
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!
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.