BookmarkSubscribeRSS Feed
Eva
Quartz | Level 8 Eva
Quartz | Level 8

Dear all,

 

My SAS program runs on a linux server. I need to access files in a directory that my user (abc) cannot acces due to user rights. So I use another user (xyz) that has read rights on the directory:

 

filename fref FTP "/project/anotherprpject/src/file_I_want_to_access.txt" 
USER = "xyz" PASS = "{SAS002}3427979DHKS79237SDHH323";

This works.

[Note: if I use DISK instead of FTP as device the statement does not work, because DISK does not allow the option USER]

 

Now. I'd like to do the same with the filename function. Can anybody give my the right syntax? Seems like I'm getting the '  , " etc. wrong.

 

data _null_;   
     length fref $8 filename $80;     
     rc = filename("fref", "/project/anotherproject/src/file_I_want_to_access.txt", "ftp",
     'USER = "xyz", PASS = "{SAS002}3427979DHKS79237SDHH323"');    
     if not fexist(fref) then do;         
          call symput ("l_sErrMsg", "file does not exist.");             
          call symput ("l_nErrRC", "-1");         
          return;        
     end;
run;

 

This doesn't work. I get the error:

 

Message:ERROR: Invalid option name ,.

 

Best wishes

Eva

5 REPLIES 5
Patrick
Opal | Level 21

According to documentation https://support.sas.com/documentation/cdl/en/hostunx/61879/HTML/default/viewer.htm#a000195127.htm 

the valid syntax for the filename function is:

FILENAME(fileref, filename <,device-type<,"host-options"<,dir-ref>>>)

 

According to this syntax (and also the example given in the docu link) you need to single quote the credential bits.

rc = filename(fref, DISK, "/project/anotherproject/src/file_I_want_to_access.txt", 
     'USER="xyz"', 'PASS="{SAS002}3427979DHKS79237SDHH323"');   

What I'm not so sure about: Can you use a SAS encoded password this way? You need to try. I have my doubts that it will work but curious what you will tell us.

Eva
Quartz | Level 8 Eva
Quartz | Level 8

Dear Patrick,

 

meanwhile I found out, that DISK doesn't allow user and password (I edited this in my orginal post). So I use ftp as described in the documentation for UNIX and filename function.

 

So I tried this with your example:

 

rc = filename (fref, FTP, "/project/anotherproject/src/file_I_want_to_access.txt, 
'user="xyz"',
'pass="{SAS002}3427979DHKS79237SDHH323"');

 

Then I tried this after I read the documentation and followed the adivice there (changed filename and device in order; set fref and ftp in quotation marks):

 

rc = filename ("fref", "/project/anotherproject/src/file_I_want_to_access.txt, 
"ftp",
'user="xyz"',
'pass="{SAS002}3427979DHKS79237SDHH323"');

 

In both cases the Error message is:

 

Message:ERROR: Invalid logical name.

 

Patrick
Opal | Level 21

Is there a double quote missing after the path/filename?

 

 

Eva
Quartz | Level 8 Eva
Quartz | Level 8

Yes, you're right.

 

I tried:

 

rc = filename ("fref", "/project/anotherproject/src/file_I_want_to_access.txt", 
"ftp",
'user="xyz"',
'pass="{SAS002}3427979DHKS79237SDHH323"');

and:

 

rc = filename ("fref", "/project/anotherproject/src/file_I_want_to_access.txt", 
"ftp",
'user="xyz",
pass="{SAS002}3427979DHKS79237SDHH323"');

and got the message:

 

Message:ERROR: Invalid logical name.

Then I added the host name:

 

rc = filename ("fref", "/project/anotherproject/src/file_I_want_to_access.txt", 
"ftp",
'user="xyz",
host="my.host.name"
pass="{SAS002}3427979DHKS79237SDHH323"');

Added the port number (7551) with a blank and in the second example with a colon:

 

rc = filename ("fref", "/project/anotherproject/src/file_I_want_to_access.txt", 
"ftp",
'user="xyz",
host="my.host.name 7551"
pass="{SAS002}3427979DHKS79237SDHH323"');
rc = filename ("fref", "/project/anotherproject/src/file_I_want_to_access.txt", 
"ftp",
'user="xyz",
host="my.host.name:7551"
pass="{SAS002}3427979DHKS79237SDHH323"');

 

and in all three cases got the message:

 

ERROR: Invalid option name                        XÌ6Ÿ+  p¥žŸ+  ðEÀŸ+          €    @fÐ6Ÿ+         ¦Réåž+  ðEÀŸ+          
                     UÀŸ+  r1Ÿ+              Ÿ+          0fÐ6Ÿ

I have no more ideas... do you?

 

Patrick
Opal | Level 21

I believe you can't use the SAS encoded password for your FTP connection. Try without encoding (just as a test, not as the final solution).

 

Let's go back to your initial problem:

"My SAS program runs on a linux server. I need to access files in a directory that my user (abc) cannot acces due to user rights. So I use another user (xyz) that has read rights on the directory:"

 

The way I normally get my UNIX/Linux commands right: I'm using Putty and try them first via command prompt.

 

In your case: Can you FTP from the same machine? Try first in Putty and only if that works try out of SAS.

 

I believe another option is to execute a command with the credentials of another user (elevated priviledges).

https://linuxacademy.com/blog/linux/linux-commands-for-beginners-sudo/  

 

I haven't done the following myself so just throwing ideas:

- Login via Putty with your normal SAS user

- Issue SUDO to change to the user with access priviledges to your file

- Test file access (eg. issuing a CAT command for your file)

- If all of the above works:

  - Use a PIPE: 
    https://support.sas.com/documentation/cdl/en/hostunx/67929/HTML/default/viewer.htm#n1ceb0xedanuj3n19...

    Write either a Shell script or combine all commands directly in the command bit of the Filename Pipe syntax.
    (I believe you need just a SUDO and a CAT).
  - Use the fileref in your data step reading the file into SAS

 

Much easier would be...

Get read access for your normal SAS user to this directory and file

 

    

 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5 replies
  • 2503 views
  • 0 likes
  • 2 in conversation