BookmarkSubscribeRSS Feed

SAS Viya 3.5 – SAS FILENAME statement to ADLS2

Started ‎06-10-2020 by
Modified ‎06-10-2020 by
Views 3,333

With the SAS Viya 3.5 release, the SAS Viya programming environment (SAS 9.4) can read and write data files to ADLS and ADLS2 using FILENAME statement. The ADLS FILENAME statement’s Azure access method enables you to access data from ADLS/2.

 

This article talks about various components involved for SAS FILENAME statement to access data files from Azure ADLS2.  

 

Pre-requisites

  • User access to Azure Storage Account with Storage Blob Data Contributor role.
  • Azure application with access permission to Azure Data lake and Azure Storage.

 

Data Path diagram

The following diagram describes the data access components and data path from SPRE/Base SAS 9.4 to ADLS2 using FILENAME statement. 

 

SAS_FLNM_Aaccess_to_ADLS2_1.png

Select any image to see a larger version.
Mobile users: If you do not see this image, scroll to the bottom of the page and select the "Full" version of this post.

 

Azure Configurations to access ADLS2

Please refer to the article CAS accessing ADLS2 and go through the “Azure configuration to access ADSL2” section.  

 

Azure information required to access ADLS2 data from CAS

To access the Azure ADLS2 data file using FILENAME statement from SPRE/SAS, you need the following information.  

 

    azuretenantid="XXXXXXXXXXXXXXXXXXXXXX"
    applicationid="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    accountname= "utkuma8adls2strg"
    filesystem="fsutkuma8adls2strg"

 

SAS FILENAME statement Authentication

An ORC LIBNAME uses device code authentication with Azure. Very first-time execution of ORC LIBNAME statement, it generates a misleading error message. It could not find the Azure access token at SAS compute server for SAS user. It created a .sasadls<>.json file under SAS user’s home directory with instructions to register the device and obtain the Azure Access token. The .sasadls<>.json file created for each SAS user. As part of the instruction, you need to login to https://microsoft.com/devicelogin Microsoft page and validate the listed device.

 

Note: The default location for the Azure authorization key file is the home directory of the SAS user (e.g /home/viyademo01/.sasadls_.jason).  

 

Error from very first-time execution of ORC LIBNAME statement:


90   ;
ERROR: Cannot obtain connection to ADLS. Check options and tokens.
ERROR: To sign in, use a web browser to open the page
https://microsoft.com/devicelogin and enter the code  to authenticate.
91

 

After you log on to listed Microsoft page a series of windows provide further instruction to authorize the device. The subsequent attempts to access the data succeed and generates an Azure authorization key file at SAS compute server under the user’s home directory.  

 

[viyademo01@intviya01 ~]$ ls -l /home/viyademo01/.sasadls*
-rw-------. 1 viyademo01 sasusers 5718 Feb 13 11:52 /home/viyademo01/.sasadls_100001.json
[viyademo01@intviya01 ~]$

 

Data read/write to ADLS2 using SAS FILENAME statement

The following code describes the data save from SPRE/SAS to ADLS2 Blob storage. In step-1, it executes the ADLS FILENAME statement. In step-2, it executes data steps to saves few lines into data file at ADLS2.  

 

Code:

/* Step-1 */
options azuretenantid="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

filename out adls "sasfile/example.txt"
applicationid="XXXXXXXXXXXXXXXXXXXXXXX-XXXXXXXXXXX"
accountname="utkuma8adls2strg"
filesystem="fsutkuma8adls2strg"
;

/* Step-2 */
data _null_;
   file out;
   put 'line 1';
   put 'line 2';
run;

 

Log extract:

…………
…………
83   options azuretenantid="b1c14d5c-3625-45b3-a430-9552373a0c2f";   /* 1*/
84
85   /** File Name Statement to ADLS2 **/
86   filename out adls "sasfile/example.txt"
87      applicationid="XXXXXXXXXXXXXXXXXXXXXXXX-xxxxxxxxxxxx"
88      accountname="utkuma8adls2strg"
89      filesystem="fsutkuma8adls2strg"
90   ;
91
92   data _null_;
93      file out;
94      put 'line 1';
95      put 'line 2';
96   run;
NOTE: The file OUT is:
      Filename=sasfile/example.txt,
      Account Name=utkuma8adls2strg,
      File system=fsutkuma8adls2strg
NOTE: 2 records were written to the file OUT.
      The minimum record length was 6.
      The maximum record length was 6.
NOTE: DATA statement used (Total process time):
      real time           0.14 seconds
      cpu time            0.01 seconds

97
….
……………
        

   

The following screenshot describes the .txt data file saved to Azure ADLS2 by executing the above statement.

 

SAS_FLNM_Aaccess_to_ADLS2_2.png

 

Important Link:

FILENAME statement: Azure Access Method  

 

Related Articles:

SAS Viya 3.5 – CAS accessing Azure Data Lake files

SAS Viya 3.5 – SAS ORC LIBNAME engine to ADLS2    

Comments

Will this method for connecting to Azure Blob work on a 9.4M6 BI server?  If not, is there an alternative approach that might work for a 9.4 server (no Viya)?

Version history
Last update:
‎06-10-2020 01:47 PM
Updated by:
Contributors

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags