BookmarkSubscribeRSS Feed

The Video Guide To Importing Local Files into CAS on SAS Viya

Started ‎05-31-2021 by
Modified ‎05-31-2021 by
Views 6,196

When you need to import a local file from your PC into CAS, on SAS Viya 2020.1 or later, these short videos will guide you. The code snippets mentioned in the video are provided in the post.

 

The Local File Import in 30 Seconds

If you only have 30 seconds, here is the condensed summary:

 

 

 

Options:

  1. Use the Visual Interfaces: SAS Environment Manager, SAS Visual Analytics, SAS Data Explorer or SAS Information Catalog.
  2. Write code: PROC CASUTIL (load file) or PROC CAS (upload action).
  3. Use the SAS Studio code snippet: generates PROC IMPORT.
  4. Use SAS Studio flow: generates a DATA STEP.
  5. Use Python with the SWAT package. Will be discussed in a separate post.

 

Use the Visual Interfaces

 

 

The SAS Viya Administration documentation does an excellent job at explaining the import options.

 

Write Code

 

 

 

Make the file available to SAS Studio

First you need to upload the file in a location which is visible and accessible by SAS Compute. The location can be:

  • A folder on a Network File Share (mypath in the code snippet below).
  • A folder in SAS Content. By default, a LOCKDOWN is enabled by default for all the SAS Compute servers. You need to take certain steps to be able to define a CASLIB on that location (folder in the code snippet below).

 

Session definition and file location

* Wrapper code;
CAS mySession  SESSOPTS=( CASLIB="casuser" TIMEOUT=999 LOCALE="en_US" metrics=true);
options msglevel=i ;
caslib _all_ assign;
%put My Userid is: &sysuserid;

* File created on NFS;
%let mypath1=/gelcontent/gelcorp/shared/data/ ;
%let csvdata=&mypath1.prdsale.csv;

* This location is in lockdown state;
*%let folder=/Users/&sysuserid/My Folder/;
*%let csvdata2=&folder.prdsale.csv;

 

See the following resources for external path based data:

 

PROC CASUTIL example

 

* Drop in-memory CAS table;
proc casutil ;    droptable casdata="prdsale_proccasutil" incaslib="casuser" quiet; quit ;

* Proc casutil - file load .csv from client machine to CAS library;
proc casutil ;
   load file="&csvdata"
        outcaslib='casuser' casout="prdsale_proccasutil" copies=0  promote; quit;

PROC CAS example

 

* Drop in-memory CAS table;
proc casutil ;
   droptable casdata="prdsale_proccas" incaslib="casuser" quiet;
quit ;

* table.upload cas action;
proc cas;
upload result=r status=rc /
path="&csvdata"
casOut={
caslib="casuser",
label="CSV file from client",
lifetime=999,
name="prdsale_proccas",
promote=TRUE,
replication=0
}
importOptions={fileType="CSV", vars={{name="ACTUAL", format="DOLLAR8.2"}}
}
;
quit;

PROC Import example

 

/* Import a csv file from the location specified on the filename statement */
/* The SAS data set created is named by substituting a name for work.mycsv */

filename csv "&csvdata.";

/* Import the CSV file  */
proc import datafile=csv out=casuser.prdsale_import replace dbms=csv;
   getnames=yes;
   run;

/* Print the first 10 observations **/
proc print data=casuser.prdsale_import(obs=10);
   run;

filename csv;

* Add a promote statement;
proc cas;
table.promote name='prdsale_import' caslib='casuser'; quit;

 

Conclusions

To import a local file into CAS:

  • Use the visual interfaces.
  • Write your own PROC CASUTIL, which should be the easiest and most efficient coding option.
  • Write a PROC CAS, if you need to fine-tune the import options.
  • Use a code snippet in SAS Studio.
  • Use SAS Studio flow, a visual interface that generates code.

References

I would recommend the following resources:

SAS Viya 2020.1 and later

SAS Viya 3.5

Acknowledgements

@StephenFoerster , @MKQueen , @NicolasRobert , @UttamKumar , @GerryNelson 

 

Thank you for your time reading this post. Please comment and share your experience with the Local File Import in CAS and help others. If you wish to get more information, please leave a comment.

 

Find more articles from SAS Global Enablement and Learning here.

Version history
Last update:
‎05-31-2021 09:50 PM
Updated by:
Contributors

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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