BookmarkSubscribeRSS Feed
alepage
Barite | Level 11

Hello,

 

We are starting a new project and I will need to read a csv file on Amazon Web Services.  I do not have a lot of information up to now but I wonder if it could be possible to get a SAS snippet showing how to connect on AWS and how to read a csv file.

 

Regards,

 

11 REPLIES 11
colingray83
SAS Employee

Hi,

 

It sounds like you need PROC S3, this reads / lists / creates files in S3 buckets. It has a variety of statements so check in support.sas.com for more details, but you will need something like:

 


/* read data in and import excel file*/
filename _s3file temp;
%let _locals3file = %sysfunc(pathname(_s3file));
/* connect to S3 */

 

proc s3 config="/home/sas/Documents/tks3.conf";
get "/XXXXsasdata/fakenames100.csv" "&_locals3file"; /* XXXXsasdata  is your bucket name */
run;

 

/* this bit hopefully works - i was using xlsx spreadsheet so haven't tested with csv */
proc import datafile =_s3file replace
dbms=csv
out=work.fake1;
getnames=yes;

run;

 

you will also need a file called tks3.conf (or you can put the details in code, but this contains something like the following)

ssl=yes
keyID=XXXXXXXX
secret=YYYYYYYYYYYYYYYYYYYYYYYY
region=euireland

 

 

Let me know how you get on - good luck.

 

Colin

alepage
Barite | Level 11

As I can see from your SAS code, we cannot read the file directly, we need to import it to read it.

Is that correct ?

Also, is there some options we can use to help in troubleshoothing proc s3? Ex: could not list bucket contents and so on

Patrick
Opal | Level 21

@alepage wrote:

As I can see from your SAS code, we cannot read the file directly, we need to import it to read it.

 


Depending on your SAS version you can use FILENAME Statement: S3 Access Method

To read the file "directly" refer to: Example 1: Reading a File by Using the S3 Access Method

colingray83
SAS Employee

Hi,

Not sure there is a debug option, though the following will list files to the log, 

 

proc s3 config="c:/temp/aws/tks3.conf";
list "XXXsasdata"; /* will list files to the log */
run;

 

I've also used with Viya a libname statement that points directly to the folder and you can then read directly in the usual way. I'm not sure how AWS transfer charges apply, so i always disconnect afterwards !

 

caslib mys3 datasource=(srctype="s3"
accesskeyid="AAAAAAAAAAAA"
secretaccesskey="BBBBBBBBBBBBBBBB"
region="EU_Ireland"
bucket="XXXXsasdata"
/* objectpath="/asr/projB" */
usessl=true);

alepage
Barite | Level 11
This more related to SAS Viya. I don't see nothing related to proc s3
alepage
Barite | Level 11

Up to now, I have made some tests but it is like SAS EG is running, running and nothing appends.

Is there some options we can use to check if the connection is granted and to check the grant for my key and secret

 

Any sample test we can do ?

Sajid01
Meteorite | Level 14

I think the best option is to create a ticket with SAS Tech Support.

alepage
Barite | Level 11
How do we create a ticket with sas tech support
Patrick
Opal | Level 21

@alepage wrote:
How do we create a ticket with sas tech support

Contact SAS Technical Support

colingray83
SAS Employee

Hi,

It might be that your organisation doesn't permit connections out to s3, as if its timing out, this sounds like it might be a connection issue. You could try using curl from a command line prompt to your s3 bucket, this would at least check if your getting a connection.

Have a look at this website and check it meets your requirements

https://www.googlinux.com/retrieving-s3-objects-using-curl/

 

regards,

 

Colin

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 11 replies
  • 2117 views
  • 0 likes
  • 4 in conversation