SAS cannot save graphs to specified destination - sas

Why can't I save the graphs to specified file as expected? Could someone help me out on this? thanks very much.
Best regards,
Mi
%macro Corr(in,out,y,x,separateBy,titleString,xSize=900pt,ySize=600pt,saveDestination="c:\sas graph",saveResolution=400);
goptions reset=all hsize=&xSize vsize=&ySize;
ods graphics on;
ods listing gpath=&saveDestination image_dpi=&saveResolution;
ods graphics / imagename='Repeat' imagefmt=jpeg;
proc reg data=&in outest=&out simple edf;
title "&titleString of #ByVal(_name_)";/*Double quotation required when macro variable present in title string*/
model &y=&x / alpha=0.05 noprint;
id bladeSerialNumber;
by &separateBy;
plot &y*&x;
run;
quit;
ods graphics off;
title '';
%mend;
*Invoke Example;
libname ro 'c:\sas output\ro';
%corr(ro.SUMMARY_SPLITBYITERATION_METHOD1,corrSummary,Iter2,Iter1,_name_,Repeatability);
Here are the partial notes from SAS:
%corr(ro.SUMMARY_SPLITBYITERATION_METHOD1,corrSummary,Iter2,Iter1,_name_,Repeatability);
WARNING: The variable _NAME_ or _TYPE_ exists in a data set that is not TYPE=CORR, COV, SSCP, etc.
NOTE: Graph's name, REG, changed to REG384. REG is already used or not a valid SAS name.
NOTE: Graph's name, REG, changed to REG112. REG is already used or not a valid SAS name.
NOTE: 29844 bytes written to C:\Users\mzhou7165825\AppData\Local\Temp\SEG8728\SAS Temporary Files\_TD9196_5K82J12A_\Prc2\reg384.png.
ERROR: Insufficient authorization to access C:\windows\system32\sasgraph.png
NOTE: The above message was for the following BY group:
NAME OF FORMER VARIABLE=Amplitude10LVGA
NOTE: Graph's name, REG, changed to REG385. REG is already used or not a valid SAS name.
NOTE: Graph's name, REG, changed to REG113. REG is already used or not a valid SAS name.

First of all please make sure that the saveDestination="c:\sas graph" is pointing to an existing folder and that you assign a filename to the output.
Check:
if you are running sas locally, that your user has write access to the folder
if you are running sas on server, that the "server user" has write access to the folder.
Second, if the first sentence evaluates to false (and also sas is running locally) then create the folder with the required user access rights.
However if you are running sas remotely, you won't be able to write to your local computer, but to the server only. In case of windows server, you can use the following syntax to save your file:
[code start]
%let mypath = C:\Users\%sysfunc(dequote(&_CLIENTUSERID))\Documents\;
this
ods pdf file= "&mypath\yourfile.pdf";
or this
ods listing gpath = "&mypath\yourfile.jpeg";
*** your code***
ods _all_ close;
[code end]

Related

SAS EG Export Excel with pass

How can I protect my excel file with a password, because in sas EG not supported DDE.
I'm using this, but I dont have the convert.vbs, so where can i get it?
/***********************************************/
/* Create a test worksheet to password protect */
/***********************************************/
ods tagsets.excelxp file="c:\temp.xml";
proc print data=sashelp.class;
run;
ods tagsets.excelxp close;
/*****************************************************************/
/* Create and excecute a script file using the input XML file */
/* and the converted XLSX file. The value 51 is needed for XLSX. */
/* Use the value of 1 for XLS files in the SaveAs command. */
/*****************************************************************/
%let XMLfile = c:\temp.xml;
%let ExcelFile = c:\temp.xlsx;
%let VBscript = ***c:\convert.vbs***;
%let password=test;
data _null_;
file "&vbscript" lrecl=200;
put 'Dim xlApp, xlWkb, SourceFile, TargetFile';
put 'Set xlApp = CreateObject("excel.application")';
put 'SourceFile="' "&XMLfile" '"';
put 'Set xlWkb = xlApp.Workbooks.Open(SourceFile)';
put 'TargetFile="' "&ExcelFile" '"';
put 'xlApp.DisplayAlerts=false';
put "xlWkb.SaveAs TargetFile, 51,""&password""";
put 'xlApp.DisplayAlerts=true';
put 'xlWkb.close';
run;
options noxwait noxsync;
x "cscript ""&vbscript""";
It appears that your code creates the file c:\convert.vbs for you and then runs it. You just need to remove the asterisks so that it's a valid file path.
If you don't have DDE it's unlikely that code will work for you either.
The last line,
x "cscript ""&vbscript""";
Is a command to your operating system. Often if DDE is disabled, this type of functionality is also disabled. You can check this by examining the XCMD option.
proc options option=xcmd;
run;
If XCMD is enabled you'll see:
XCMD Enables the X command in SAS.
You can only change that setting at start up and sometimes need to be an administrator as well.

Writing ODS file to local machine from EG Server

I am using EG based on a SAS 9.4.2.0 installation and am trying to string a set of proc reports together using ODS LAYOUT, then have the report generated from this form the tab of an Excel file using TAGSET.EXCELXP as so:
ods listing close;
ods tagsets.excelxp file='E:\myfolder\myfile.xml'
options(
frozen_rowheaders='no' sheet_interval='none' sheet_name='sheet1'
autofilter='all' autofilter_table='2');
ods layout gridded columns=2 rows = 2;
ods region;
proc report data = mydata1;
title = 'some title';
run;
ods region;
proc report data = mydata2;
title = 'some title';
run;
ods layout end;
ods tagsets.excelxp options(sheet_interval='none' sheet_name='sheet2');
ods layout gridded columns=2 rows = 2;
ods region;
proc report data = mydata1;
title = 'some title';
run;
ods region;
title = 'some title';
run;
ods layout end;
ods tagsets.excelxp options(sheet_interval='none' sheet_name='sheet3');
ods layout gridded columns=2 rows = 2;
ods region;
proc report data = mydata1;
title = 'some title';
run;
ods region;
proc report data = mydata2;
title = 'some title';
run;
ods layout end;
ods tagsets.excelxp close;
ods listing;
However I am getting both a warning that TAGSET.EXCELXP does not exist, but also an error that indicates SAS thinks my local drive for saving the Excel file to is a sub folder of the SAS config folder on the network.
What have I done wrong?
Thanks
If your E:\ path is a local path (meaning a local disk), then the SAS Server cannot see it. You'll need to instead write that to a path that the SAS Server can see. If you're not sure what paths the SAS Server can see, please contact your SAS administrator; depending on the installation the server may be able to see your normal network shares, or it may be limited to only certain locations.
If E:\ is mapped to a network share, you may need to submit the network share UNC path, usually \\organization\path\to\file\ structure or similar.
You can also use the Copy Files custom task in Enterprise Guide; see There and Back Again, and if you're in EG 7 you can do this from the Tasks->Data menu. This would work if you write the file to your SAS Server's local storage (such as in the work directory or other local directory) and then use the copy files task to your local drive.

SAS ODS Documentation Syntax Error

I have many questions regarding the ODS system and am trying to educate myself. However, I am unable to do so as the SAS documentation example generates an error.
The documentation in question is Controlling Where Your Output Is Stored.
The very first example is, verbatim,
/* Specify the ODS output path */
filename odsout ".";
goptions reset=all;
ods _all_ close;
ods pdf path=odsout file="mygraph.pdf";
proc gchart data=sashelp.prdsale;
vbar Product / sumvar=actual;
title1 "First Quarter Sales in Canada";
where Quarter=1 and Country="CANADA";
run;
quit;
ods pdf close;
ods html; /* Not required in SAS Studio */
It appears that the "." in the filename statement is a place holder akin to "C:\your\file\path\here\".
I have replaced that with "C:\output". When I do this, I get the following error:
6 ods pdf path=odsout file="mygraph.pdf";
----
22
76
ERROR 22-322: Syntax error, expecting one of the following: ;, (, ANCHOR, AUTHOR, BACKGROUND, BASE,
BODY, BOOKMARK, BOOKMARKGEN, BOOKMARKLIST, BOX_SIZING, CLOSE, COLOR, COLUMNS, COMPRESS,
CONTENTS, CSSSTYLE, DISPLAY, DOM, DPI, EXCLUDE, FILE, FONTSCALE, GFOOTNOTE, GTITLE,
HOST, KEYWORDS, NAMED_DEST, NEWFILE, NOBACKGROUND, NOBOOKMARKGEN, NOBOOKMARKLIST,
NOCOLOR, NOCONTENTS, NOGFOOTNOTE, NOGTITLE, NOPDFNOTE, NOTOC, PACKAGE, PCL, PDF,
PDFMARK, PDFNOTE, PDFTOC, PRINTER, PS, SAS, SELECT, SGE, SHOW, STARTPAGE, STYLE,
SUBJECT, TEXT, TITLE, UNIFORM.
ERROR 76-322: Syntax error, statement will be ignored.
Am I doing something wrong or did the author of this example not compile before publishing?
It seem that path option is valid in ods html, but is not valid in ods pdf, but it doesn't matter because you can specify absolute path in file option.
ods pdf file="C:\temp\mygraph.pdf";

HTML output in SAS

I only see results of my SAS programs in Log like:
16488 title '6';
16489
16490 ods html file = 'E:\Dev\ka\body1.html';
16491
16492
16493 proc means data=learn.blood;
16494 var RBC WBC;
16495 output out = means mean = M_RBC M_WBC;
16496 run;
It's not show any error, but I don't see results in html file.
How to turn on html output?
You may have the setting 'Show results as they are generated' off.
Check your preference settings.
Confirm your HTML file is created as well, though you may need to include a CLOSE before it is fully available.
ods html file = 'E:\Dev\ka\body1.html'
proc means data=sashelp.class;
var height weight;
output out=means mean=M_Height M_Weight;
run;
ods html close;
Works fine for me. I adapted your code slightly to test it:
ods html file="%sysfunc(pathname(work))\body1.html";
proc means data=sashelp.class;
var height weight;
output out=means mean=M_Height M_Weight;
run;
%put Your file has been output to: %sysfunc(pathname(work))\body1.html;
I am seeing results. Are you sure you have observations in your dataset and that there are no errors or warnings being printed to the log?

How to obtain value of estimated parameters in SAS (proc phreg)?

How to obtain value of estimated parameters in SAS (proc phreg) ? I have been searching syntax OUTPUT and baseline but they gives only value XBETA ets.
I'm not into statistics, so I'm just guessing what value you mean - here's an example I think could help you:
ods trace on;
ods output ParameterEstimates=work.my_estimates_dataset;
proc phreg data=sashelp.class;
model age = height;
run;
ods trace off;
This is using SAS Output Delivery System component of SAS/Base.
With ods trace on;, you'll see references to parts of procedure output in SAS log:
Output Added:
-------------
Name: ParameterEstimates
Label: Maximum Likelihood Estimates of Model Parameters
Template: Stat.Phreg.ParameterEstimates
Path: Phreg.ParameterEstimates
You can refer to those (usually by Name or Path) and store them in a table with ODS OUTPUT... statement.
Look for SAS ODS user guide for more.