insufficient authorization to access external CSV files in sas studio - sas

Here is the code.
data test;
infile '/folders/myfolders/smile.txt';
run;
ods csvall file='c:\test.cvs';
proc print data=WORK.ONE;
var Name Score Grade;
by IdNumber;
run;
ods csvall close;
The first data step runs well. The main issue is with the ods part. I got the insufficient authorization to access the csv file error in logs. Could anyone tell me why? Many thanks for your time and attention.
EDIT: So sorry for the mistake. For the second block of the code, that is actually this:
ods csvall file='/folders/myfolders/test.csv';
proc print data=WORK.ONE;
var Name Score Grade;
by IdNumber;
run;
ods csvall close;

To my knowledge, code you submit in SAS Studio is run on the server to which you're connected.
The first datastep reads from a (Unix) server path (forward slashes to delimit folders). The second block of code is trying to write out to a Windows drive (drive letter and backslash delimiters), but as the code is running on the Unix server, it knows nothing of your local (Windows) environment.

Related

list all SAS members in a ZOS libray from remote sas session

On our ZOS (mainframe) we have a library called
USER.PGM.WEEKLY
where several sas programs(members) are located
I am trying to retrieve a list of all the member from my PCSAS with following code
rsubmit;
proc source indd='C009BSA.BSA.BIBHLP.SAS' select *; print;run;
endrsubmit;
signoff;
But it errors out with
ERROR 22-322: Syntax error, expecting one of the following: ;, DIRDD, INDD, MAXIOERROR, NOALIAS,
NODATA, NOMEM, NOPRINT, NOSUMMARY, NOTSORTED, NULL, OUTBLK, OUTDD, PAGE, PRINT,
SEARCH.
ERROR 180-322: Statement is not valid or it is used out of proper order.
I have tried to google around to find the solution but haven't been able to sort it out.
How ever i am able to download one member at the time by running
filename inpds 'USER.PGM.WEEKLY' shr;
proc download infile =inpds(PPRINT_TO_PDF)
outfile='L:\Work\PPRINT_TO_PDF';
run;
Try something like this. You might need to use an actual physical file instead of using the TEMP filename engine on ZOS.
filename dirlist temp;
rsubmit;
filename dirlist temp;
proc source indd='C009BSA.BSA.BIBHLP.SAS' dirdd=dirlist; run;
proc download infile=dirlist outfile=dirlist; run;
endrsubmit;
https://v8doc.sas.com/sashtml/os390/z0217440.htm
If you just want to download all of the members of the PDS then PROC DOWNLOAD can do that for you without you needing to have the list of members.
filename outdir '/where/I/want/to/write/';
rsubmit;
filename indir 'C009BSA.BSA.BIBHLP.SAS';
proc download infile=indir(*) outfile=outdir; run;
endrsubmit;

SAS ODS not to open output

In the following code, I would like to print an excel sheet and do not open it once the code ends, does anyone know how to do this because the ods excel close does not work. There is an option in the SAS 9.4 platform to not open the output but when I choose than and open a new SAS session the option is reverted. Anyone knows something about it? Thanks :)
ods listing close;
ods excel file="path.xlsx"
/*ods excel file="path.xlsx"*/
/* will apply an appearance style */
/*style=calibri*/
options(
/* for multiple procs/sheet */
sheet_interval="none"
/* name the sheet tab */
sheet_name="filename"
);
/* add some formatted text */
ods escapechar='~';
ods text="~S={font_size=14pt font_weight=bold}~filename";
proc print data=data noobs;
run;
ods excel close all;
ods listing;
Tazz:
Problem
You should look at the SAS log for ERROR messages. In future questions be sure to add ERROR messages. Do you get this message ? (### is the source code line number)
### ods excel close all;
---
22
202
ERROR 22-322: Syntax error, expecting one of the following: ;, ANCHOR, AUTHOR, BOX_SIZING,
CATEGORY, CLOSE, COMMENTS, CSSSTYLE, DOM, DPI, FILE, GFOOTNOTE, GTITLE, IMAGE_DPI,
KEYWORDS, NOGFOOTNOTE, NOGTITLE, OPTIONS, SASDATE, STATUS, STYLE, TEXT, TITLE,
WORK.
ERROR 202-322: The option or parameter is not recognized and will be ignored.
So, this statement of yours is invalid
ods excel close all;
Fix
Use instead either
ods excel close;
or
ods _all_ close;
Be forewarned, the first time you run the code Excel will open the output. If you leave the results open in Excel and run the code again you will get a different ERROR:
ERROR: File is in use, ....
because the destination will still be open and SAS will not be able to write to it.
Turn off results viewing
ODS RESULTS OFF;
The ODS destination will be written to. The automatic viewing of results and results tracking as new items in the Results tab will not happen.
The setting is not programmed in, it's in the GUI.
Tools>Options>Preferences>Results
Uncheck: View results as they are generated

SAS ODS Query/Statement print along with it's output

SAS EG
Is there any way I can print the query/statement used to get the output, along with the output, using SAS ODS?
Suppose,
ods pdf file=pdfile;
proc sql;
select a.*
from tab1 a inner join tab2 b
on a.something=b.something
where <>
having <>;
quit;
ods _all_ close;
this would print the OUTPUT generated from the above query. But can I also get the query printed via the ods pdf along with the output?
There's no automatic way to redirect the log that I'm aware of.
There are a few ways to get what you want, however.
First off, if you are able to use Jupytr, SAS has plugins to enable that to work with SAS, and then you can simply write in the notebook and run the code, and the results appear with your code just as you want. See Chris Hemedinger's blog post on the subject for more details.
Second, SAS Studio will support a notebook-style interface probably with the next major revision (I believe version 5.0) which will release late next year. So similarly, you would put your code and get your output in the same windows.
Finally, the third option is to do as Reeza suggested - write to a log file, then print that to the output. It's messy but possible.
Here's an example of the latter. I don't make any effort to clean it up, note, you'd probably want to remove the logging related to PROC PRINTTO and the otehr notes (or turn on NONOTE).
ods pdf file="c:\temp\test.pdf";
filename logfile temp;
proc printto log=logfile;
run;
proc sql;
select * from sashelp.class;
quit;
proc printto;
run;
data _null_;
infile logfile;
input #1 #;
call execute(cats('ods text="',trim(_infile_),'";'));
run;
ods _all_ close;

SAS suppress .lst files but keep ODS output

I was doing a PCA analysis with SAS using the following code:
ods output Eigenvectors=PRINCEEV Eigenvalues=PRINCEEVAL;
proc princomp data=REPLACED PLOTS=SCORE(ELLIPSE NCOMP=5) NOPRINT;
id time;
run;
ods output close;
Because the lst files this analysis produces is too large, I used the NOPRINT option. However, it seems that the NOPRINT option also eliminates all of my ODS outputs. (Now PRINCEEV and PRINCEEVAL are all empty):
ERROR: File WORK.PRINCEEVAL.DATA does not exist.
ERROR: Export unsuccessful. See SAS Log for details.
259 putn
_______
1
259 ! ame=YES; run;
WARNING 1-322: Assuming the symbol PUTNAMES was misspelled as putname.
ERROR: File WORK.PRINCEEV.DATA does not exist.
ERROR: Export unsuccessful. See SAS Log for details.
ERROR: Errors printed on page 1.
Is there a way to suppress the generation of lst file, without affecting the ods output?
UPDATE:
It seems that according to the following sas blog, it is not possible to do that:
Can you combine NOPRINT and ODS OUTPUT?
SAS programmers crave efficiency. Upon reading that the NOPRINT option
can make a procedure run faster, the ambitious programmer might
attempt to run a procedure with the NOPRINT option but use the ODS
OUTPUT statement to capture the results of one table. Sorry, friend,
but you can't do that. The NOPRINT option means that no ODS tables are
created, so there is no way to select a table and save it to a data
set.
But the dilemma is, I have limited space on the cloud computing server. The lst files are doing nothing but wasting my spaces. Deleting the lst files when SAS programs are running with external processes will also produce an io error in SAS (I already tried that).
Is there anyway around?
I would suggest:
ods listing close ;
ods output Eigenvectors=PRINCEEV Eigenvalues=PRINCEEVAL;
proc princomp data=REPLACED PLOTS=SCORE(ELLIPSE NCOMP=5) NOPRINT;
id time;
run;
ods output close;
This will close the listing destination, so should work fine.
I noticed in a related blog post, Rick argued for:
ods exclude _all_ ;
http://blogs.sas.com/content/iml/2015/05/28/five-reasons-ods-exclude.html
Minor change to the previous answer: remove the NOPRINT option and after the ODS OUTPUT is created open up the ods listing if you have further code.
ods listing close ;
ods output Eigenvectors=PRINCEEV Eigenvalues=PRINCEEVAL;
proc princomp data=REPLACED PLOTS=SCORE(ELLIPSE NCOMP=5) /*NOPRINT*/;
id time;
run;
ods output close;
ODS LISTING;
If you execute your sas-script on your cloud computing server via bash, then you can send your .lst files to /dev/null:
sas -print /dev/null script.sas
The -print option only effects your .lst, but not any ODS related outputs.

exporting sas stored process output

I created a stored process but I want to export the output to Excel. My usual export statement doesn't work in the stored process.
%let _ODSDEST=none;
%STPBEGIN();
data x;
set sashelp.class;
run;
proc export data=x outfile = "//my documents/sp_test.xlsx" dbms=xlsx replace;
sheet="table1";
run;
* Begin EG generated code (do not edit this line);
;*';*";*/;quit;
%STPEND;
Is there a way to get this to work in the stored process?
One way to have a stored process return an excel file (actually in this case it's an xml file that excel will happily open) is to use ODS to output tagsets.excelxp (xml).
When you do this, you can use stpsrv_header to modify the HTML header. The first statement tells the browser to open the file with excel, the second tells it the file name. I believe for this header modification to work the stored process needs to deliver streaming results, not package results. But I could be wrong.
When I run below, I get a file download dialog box from the browser, allowing me to open or save the file. I'm running from Stored Process Web App, but should work fine when called from Information Delivery Portal.
%let _odsdest=tagsets.excelxp;
%let rc=%sysfunc(stpsrv_header(Content-type,application/vnd.ms-excel));
%let rc=%sysfunc(stpsrv_header(Content-disposition,attachment%str(;) filename=MyExcelFile.xls));
%stpbegin()
proc print data=sashelp.shoes (obs=&obs);
run;
%stpend()
did u check with your spelling proc exportd and outfile='mypath/my documents/myoutpt.xlsx' dbms=xlsx or outfile='mypath/my documents/myoutpt.xls' dbms=xls?? U can try with ODS also.
You can also try setting your STP up as a streaming web service, removing the %STPBEGIN and %STPEND macros, and sending to _webout using this macro: https://core.sasjs.io/mp__streamfile_8sas.html
The benefit of this, is that your code will subsequently work on Viya as well.