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.
If you only have 30 seconds, here is the condensed summary:
Options:
The SAS Viya Administration documentation does an excellent job at explaining the import options.
First you need to upload the file in a location which is visible and accessible by SAS Compute. The location can be:
* 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:
* 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;
* 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;
/* 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;
To import a local file into CAS:
I would recommend the following resources:
@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.
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!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.