BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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秒
6 REPLIES 6
DavidJ
Calcite | Level 5
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.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
deleted_user
Not applicable
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
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
art297
Opal | Level 21
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
deleted_user
Not applicable
Thanks a lot, Your suggestion is very useful for me! I will realize it later.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 1204 views
  • 0 likes
  • 4 in conversation