DATA Step, Macro, Functions and more

how can i get the external file information

Reply
N/A
Posts: 0

how can i get the external file information

Hi, All!

When I read a external file into SAS Base, At the Log, There are some file information export, How can I get them into SAS variables? Such as file size, Modify time, Create time. If the file is not exist, How can i get the not exist information?
There is a sample as following.

NOTE: 没有为文件引用名“#LN00206”(用于文件“C:\lsdata\20100721_03_010407_D_0001_P_00.verf”)指定编码。
该文件中的字节顺序标记表明数据是以“utf-8”编码的。该编码将用于处理该文件。
NOTE: Infile "C:\lsdata\20100721_03_010407_D_0001_P_00.verf" 是:
文件名=C:\lsdata\20100721_03_010407_D_0001_P_00.verf,
RECFM=V,LRECL=1536,文件大小(字节)=216,
上次修改时间=2010年09月10日 15时50分33秒,
创建时间=2010年09月08日 15时15分02秒
Contributor
Posts: 32

Re: how can i get the external file information

The FILEEXIST function can check for file existence. Read up on that. As for information on the specific file once defined with a FILENAME statement, I am going to defer to Cynthia or Scott. I don't know if there is a SASHELP view that can be queried for external files like there is for LIBNAMEs.

You should probably post some code and logs in english as well. I can't understand what is being displayed right now.
Super Contributor
Super Contributor
Posts: 3,174

Re: how can i get the external file information

You have the SAS CALL function FINFO to obtain file attribute information.

You will want to use the SAS "companion" document for your SAS version and your Operating System (OS) environment, in addition to the SAS Language documentation for all the details about FINFO for your particular OS environment.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

file information create date size finfo site:sas.com Message was edited by: sbb
N/A
Posts: 0

Re: how can i get the external file information

Thanks a lot, My SAS version is 9.2, The question is as following:

Program Code:
data verfile datafile;
format dd $ 256.;
infile "C:\lsdata\20100721_03_010407_D_0001_P_00.verf" dlm=',';
retain i 1;
retain filenum 0;
input dd;
if i=1 then do;
filenum = input(dd,8.);
output verfile;
end;
else output datafile;
i = i+1;
run;


Note messages:
NOTE: No encoding was specified for the fileref "#LN00011" (for the file
"C:\lsdata\20100721_03_010407_D_0001_P_00.verf"). A byte order mark in the file
indicates that the data is encoded in "utf-8". This encoding will be used to
process the file.
NOTE: The infile "C:\lsdata\20100721_03_010407_D_0001_P_00.verf" is:
Filename=C:\lsdata\20100721_03_010407_D_0001_P_00.verf,
RECFM=V,LRECL=1536,File Size (bytes)=216,
Last Modified=10Sep2010:15:50:33,
Create Time=08Sep2010:15:15:02

NOTE: 3 records were read from the infile
"C:\lsdata\20100721_03_010407_D_0001_P_00.verf".
The minimum record length was 1.
The maximum record length was 103.
NOTE: The data set WORK.VERFILE has 1 observations and 3 variables.
NOTE: The data set WORK.DATAFILE has 2 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.35 seconds
cpu time 0.06 seconds

The question is as following:
1. get the file size into sas variable as it is in the note of "File Size (bytes)=216"
2. get the file modify time into sas variable as it is in the note of "Last Modified=10Sep2010:15:50:33"

Message was edited by: wolf Message was edited by: wolf
Super Contributor
Super Contributor
Posts: 3,174

Re: how can i get the external file information

And I referred you to the SAS companion for your OS - that would be SAS 9.2 Windows Companion and the discussion about the CALL function FINFO.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

sas 9.2 companion +windows +finfo site:sas.com
PROC Star
Posts: 7,364

Re: how can i get the external file information

Wolf,

You can probably get what you want by following Scott's advice and I recommend that you do. However, usually with SAS, there are usually multiple ways of accomplishing the same things.

If you are asking if you can parse the log to get what you want, the answer is yes.

For example, if you precede your code by running a proc printto, you can reroute the log so that you can analyze it like any other file.

In your case, possibly something like:

proc printto log= "c:\thelog.txt" new;
run;

data verfile datafile;
format dd $ 256.;
infile "C:\lsdata\20100721_03_010407_D_0001_P_00.verf" dlm=',';
retain i 1;
retain filenum 0;
input dd;
if i=1 then do;
filenum = input(dd,8.);
output verfile;
end;
else output datafile;
i = i+1;
run;

/* Re-route the log back to normal */
proc printto;
run;

data want;
infile "c:\thelog.txt" dlm=',';
format last_modified create_time datetime21.;
input @ 'File Size (bytes)=' file_size;
input @ 'Last Modified=' last_modified datetime18.;
input @ 'Create Time=' create_time datetime18.;
output;
run;

HTH,
Art
N/A
Posts: 0

Re: how can i get the external file information

Thanks a lot, Your suggestion is very useful for me! I will realize it later.
Ask a Question
Discussion stats
  • 6 replies
  • 263 views
  • 0 likes
  • 4 in conversation