Hello,
we are able to extract the last modified date of a file on Linux using the following code,
and we would like to extract similar information from a web server/ local.
* Running on a Linux folder ;
filename myfile '/opt/sas/spf/xyz/abc.csv' ; |
data last_updated ; |
opt=FOPTNAME(FOPEN('myfile'),5) ; |
optval=FINFO(FOPEN('myfile'),upcase(opt)) ; |
run ; |
Here we get the required information
Last Modified | 31Jan2023:15:29:01 |
However a log ERROR appears for running on a web server/windows :
filename fileref 'C:\Temp\abc.csv' ; |
data a(drop=fid); |
infile fileref truncover obs=1; |
fid=fopen('fileref'); |
moddate=finfo(fid,'Last Modified'); |
run; |
ERROR: Physical file does not exist, /opt/sas/config/Lev1/SASApp/C:\Temp\abc.csv.
Do we need to install Samba in order to solve this issue ? another solution you might have ? What would the code be ? Thanks a lot |
It looks like the file you are referencing is not on the server, but on a local C drive. Since SAS is running on the server, it cannot "see"/access the files on your local machine. For this to work, those files would need to be somewhere that the SAS server can access. If your SAS is running on Linux, then this could be a network file share/Samba share (which you mentioned).
The main thing to remember is that all file references in SAS code must be coded to access from the SAS environment, not your local machine, if the SAS environment is running on a central server.
It looks like the file you are referencing is not on the server, but on a local C drive. Since SAS is running on the server, it cannot "see"/access the files on your local machine. For this to work, those files would need to be somewhere that the SAS server can access. If your SAS is running on Linux, then this could be a network file share/Samba share (which you mentioned).
The main thing to remember is that all file references in SAS code must be coded to access from the SAS environment, not your local machine, if the SAS environment is running on a central server.
Hello, We get the same error if the csv is local or if it is located on the web and not at the Linux server.
Thanks your reply is helpful.
@J111 wrote:
Hello, We get the same error if the csv is local or if it is located on the web and not at the Linux server.
Thanks your reply is helpful.
Do you get the error the FIRST time you run that code? Or the only on the second, third, etc ?
You did not CLOSE the file you OPENED.
data a(drop=fid);
infile fileref truncover obs=1;
fid=fopen('fileref');
moddate=finfo(fid,'Last Modified');
fid=fclose(fid);
run;
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.
Ready to level-up your skills? Choose your own adventure.