BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

I want to use finfo function to gather some information about the data set ,for example: who created it (user name), date it was last modifies and so on

 

I saw the following code but I need to adjust it.

I have library name R_R

and I have data set name MACHZOR_TBL_SOFI

In the code it is written differently as file path and library path

filename fileref "J:\Tests.csv";
filename filerefa "J:\Facilities.csv";

What is the way to use the code by usine library name and data set name?

Please note that library R_R path is 

/usr/local/SAS/SASUsers/LabRet/Credit_Scoring_Users/R_R

 


filename fileref "J:\Tests.csv";  
filename filerefa "J:\Facilities.csv"; 
data a(drop=fidlab fidreg);                                                                                                                       
   infile fileref truncover obs=1;      
   infile filerefa truncover obs=1;    
   fidlab=fopen("fileref");
   fidreg=fopen("filerefa");
   moddatelab=input(finfo(fidlab,"Last Modified"),datetime.);
   moddatereg=input(finfo(fidreg,"Last Modified"),datetime.);
   crdatelab=input(finfo(fidlab,"Create Time"),datetime.);
   crdatereg=input(finfo(fidreg,"Create Time"),datetime.);
   labdate=datepart(max(moddatelab,crdatelab));
   regdate=datepart(max(moddatereg,crdatereg));
   format moddatelab moddatereg crdatelab crdatereg datetime. labdate regdate date9.;
   CALL SYMPUTX("labtime",put(labdate,date9.)) ;
   CALL SYMPUTX("regtime",put(regdate,date9.)) ; 
run; 

 

 

9 REPLIES 9
Kurt_Bremser
Super User

Use the FOPTNUM and FOPTNAME functions to get tge names of the available FINFO items.

UNIX does not have the concept of a "create time", BTW. Only the last modification is kept.

Kurt_Bremser
Super User

The filename of your dataset file would be

/usr/local/SAS/SASUsers/LabRet/Credit_Scoring_Users/R_R/machzor_tbl_sofi.sas7bdat

The names of available FINFO items for the different platforms are documented here: FINFO Function (Maxim 1)

Ronein
Onyx | Level 15

Thanks

What is the difference between fileref and  filerefa?

As I understand the purpose of the function is to check information about specific file (for example: when created and so on).

Why are there 2 files defined in the code?

 

filename fileref "J:\Tests.csv";
filename filerefa "J:\Facilities.csv";

Kurt_Bremser
Super User

Read the code.

  • Where are the file references used?
  • What do the functions do in which they are used as arguments? Maxim 1: Read the Documentation!
Ksharp
Super User

It looks like you can not get table owner information by FINFO.

As @Tom said try PROC CONTENTS ,about other info you also could get them by PROC CONTENTS.

 

libname x 'c:\temp\a\';
ods select none;
ods output    Attributes=want1 EngineHost=want2;
proc contents data=x.have varnum;run;
ods select all;

Ksharp_0-1724138563038.png

 

Kurt_Bremser
Super User

FINFO does return the owner:

libname mylib "/home/kurt.bremser/mylib";

data mylib.class;
set sashelp.class;
run;

data properties;
length name value $30;
rc = filename("ds","/home/kurt.bremser/mylib/class.sas7bdat");
fid = fopen("ds");
if fid /* fopen was successfull, otherwise fid would be 0 */
then do;
  do i = 1 to foptnum(fid);
    name = foptname(fid,i);
    value = finfo(fid,name);
    output;
  end;
  rc = fclose(fid);
end;
rc = filename("ds");
keep name value;
run;

proc print data=properties noobs;
run;

(executed on SAS On Demand)

Result:

name	value
Dateiname	/home/kurt.bremser/mylib/class
Besitzername	kurt.bremser
Gruppenname	oda
Zugriffsberechtigung	-rw-r--r--
Zuletzt geändert	22. August 2024 12.09 Uhr
Dateigröße (Byte)	262144

Note that the names and the last modification time are locale-dependent, so it would be better to get a certain item by its number:

value = finfo(fid,foptname(fid,i));

i should be 2 for the owner.

ballardw
Super User

Operating system dependent. On a windows system running code pointing to a different file (obviously)

 

name                 value

Filename             X:\Data\IPP\Data\hd6_2024.sas7
RECFM                V
LRECL                32767
File Size (bytes)    131072
Last Modified        07Jun2024:09:55:26
Create Time          13Feb2024:14:27:56
Kurt_Bremser
Super User

@ballardw wrote:

Operating system dependent. On a windows system running code pointing to a different file (obviously)

 

name                 value

Filename             X:\Data\IPP\Data\hd6_2024.sas7
RECFM                V
LRECL                32767
File Size (bytes)    131072
Last Modified        07Jun2024:09:55:26
Create Time          13Feb2024:14:27:56

Well, CP/M never had the concept of an owner 😉

Ksharp
Super User
Kurt,
As ballardw said, Windows OS is unable to show it , unfortunately mine is Windows OS.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 1750 views
  • 2 likes
  • 4 in conversation