Hi,
I am very new to SAS and I have a question:
I want to simply upload a CSV file in memory and then show it in a report.
I already wrote a code for it using an import proc:
filename csvFile url "https://somewebsite.com/file.csv";
libname dbgroup '/home/myusername@gmail.com';
proc import datafile=csvFile out=dbgroup.file1 replace dbms=csv;
run;
I can see the table loaded in "dbgroup" but it is not shown in the list of in memory tables to which a report has access.
So my question is how can I load this table in memory so that I can use it in my report?
I think you need to save/promote the table so you can see it there:
/* Start a CAS session */
cas casauto sessopts=(caslib="casuser");
/* Store the CSV to a temp file. */
filename scrdata temp;
proc http
url='https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-regioni/dpc-covid19-ita-regioni-latest.csv'
out=scrdata;
run;
/* Drop the existing table if present. */
proc casutil;
droptable casdata="covdata" incaslib="casuser";
quit;
/* Upload the CSV to CAS. */
proc cas;
upload
path="%sysfunc(pathname(scrdata))"
casOut={caslib="casuser", name="covdata"}
importOptions="csv";
run;
table.tableInfo /
caslib="casuser",
table="covdata";
quit;
/* One of the column names was over 32 characters so fix that. */
proc casutil;
altertable casdata="covdata"
columns =
{
{name= "totale_positivi_test_antigenico_rapido" rename="totale_pos_test_antigen_rapido"}
};
/* Save the file in casuser and promote the table. */
save casdata="covdata" replace;
promote casdata="covdata" incaslib="casuser";
quit;
/* Remove the temp file. */
filename scrdata clear;
/* End the cas session */
cas casauto terminate;
What do you mean by "in memory"? Are you using VIYA? If so you need to do something to move the SAS7BAT file that PROC IMPORT created into the viya's memory.
yes I am using Sas Viya.
I tried to move the SAS7BAT file that PROC IMPORT created into the viya's memory as you suggested. I tried "Sas Explorer" -> "import tab" and I selected folder as data source, however I cannot see the location of SAS7BAT file which is
/home/myemail@gmail.com
Moreover, I tried to import the csv file into a different folder:
filename csvFile url "https://somewebsite.com/file.csv";
libname dbgroup '/Users';
proc import datafile=csvFile out=dbgroup.file1 replace dbms=csv;
run;
but I receive the following error:
ERROR: Library dbgroup does not exist.
isn't there any solution that imports the URL of CSV directly to Viya? Especially considering that if it is a scheduled task, then two steps need to be performed.
Looking at this page
It seems you need to run code like this to load a dataset.
proc casutil ;
load data=dbgroup.file1
outcaslib="casuser" casout="&gateuserid._DATA_file1" copies=0 replace
;
quit;
I wrote the following code that ends without any error:
cas mySession sessopts=(caslib=casuser timeout=1800 locale="en_US"); filename csvFile url "https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-regioni/dpc-covid19-ita-regioni-latest.csv"; libname covid '/home/myusername@gmail.com'; proc import datafile=csvFile out=covid.regioni replace dbms=csv; run; proc casutil ; load data=covid.regioni outcaslib="casuser" casout="myusername@gmail.com.regionicas" copies=0 replace ; quit;
"proc import" creates regioni table.
but still I don't see regionicas table any where in in-memory tables:
any hint how can I fix it?
I think you need to save/promote the table so you can see it there:
/* Start a CAS session */
cas casauto sessopts=(caslib="casuser");
/* Store the CSV to a temp file. */
filename scrdata temp;
proc http
url='https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-regioni/dpc-covid19-ita-regioni-latest.csv'
out=scrdata;
run;
/* Drop the existing table if present. */
proc casutil;
droptable casdata="covdata" incaslib="casuser";
quit;
/* Upload the CSV to CAS. */
proc cas;
upload
path="%sysfunc(pathname(scrdata))"
casOut={caslib="casuser", name="covdata"}
importOptions="csv";
run;
table.tableInfo /
caslib="casuser",
table="covdata";
quit;
/* One of the column names was over 32 characters so fix that. */
proc casutil;
altertable casdata="covdata"
columns =
{
{name= "totale_positivi_test_antigenico_rapido" rename="totale_pos_test_antigen_rapido"}
};
/* Save the file in casuser and promote the table. */
save casdata="covdata" replace;
promote casdata="covdata" incaslib="casuser";
quit;
/* Remove the temp file. */
filename scrdata clear;
/* End the cas session */
cas casauto terminate;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.