<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to have a SAS Stored Process return a csv in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-have-a-SAS-Stored-Process-return-a-csv/m-p/504069#M134843</link>
    <description>&lt;P&gt;All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;I have a stored process that I have developed and it is able to return an XML when invoked using a SOAP call. However, in the response, SAS automatically encodes the response and returns "&amp;lt;" as "&amp;amp;lt".&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;I would like to request to request your help for :&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Is there a way to ensure that SAS response does not have this encoded ? (Please note that, I have already tried reading the XML response as a string and using&amp;nbsp; tranwrd function to replace the "&amp;lt;" and also using htmldecode function. However, in both the cases, the "&amp;amp;lt" still remains&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Is there a way to respond with a '.csv' file when the SAS stored process is called ?&amp;nbsp; (Kindly provide an example)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Appreciate your help&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&amp;nbsp;&lt;BR /&gt;uday&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 14 Oct 2018 02:58:37 GMT</pubDate>
    <dc:creator>UdayGuntupalli</dc:creator>
    <dc:date>2018-10-14T02:58:37Z</dc:date>
    <item>
      <title>How to have a SAS Stored Process return a csv</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-have-a-SAS-Stored-Process-return-a-csv/m-p/504069#M134843</link>
      <description>&lt;P&gt;All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;I have a stored process that I have developed and it is able to return an XML when invoked using a SOAP call. However, in the response, SAS automatically encodes the response and returns "&amp;lt;" as "&amp;amp;lt".&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;I would like to request to request your help for :&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Is there a way to ensure that SAS response does not have this encoded ? (Please note that, I have already tried reading the XML response as a string and using&amp;nbsp; tranwrd function to replace the "&amp;lt;" and also using htmldecode function. However, in both the cases, the "&amp;amp;lt" still remains&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Is there a way to respond with a '.csv' file when the SAS stored process is called ?&amp;nbsp; (Kindly provide an example)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Appreciate your help&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&amp;nbsp;&lt;BR /&gt;uday&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Oct 2018 02:58:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-have-a-SAS-Stored-Process-return-a-csv/m-p/504069#M134843</guid>
      <dc:creator>UdayGuntupalli</dc:creator>
      <dc:date>2018-10-14T02:58:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to have a SAS Stored Process return a csv</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-have-a-SAS-Stored-Process-return-a-csv/m-p/504092#M134855</link>
      <description>Hi:&lt;BR /&gt;  Yes, there is a way to have your stored process return a CSV file. However, you typically need to change the content-type header and the ODS destination BEFORE your %STPBEGIN call. Are you using %STPBEGIN/%STPEND around your main stored process code?&lt;BR /&gt;&lt;BR /&gt;Look at the CSV example (the last example) on this Tech Support note: &lt;A href="http://support.sas.com/kb/32/634.html" target="_blank"&gt;http://support.sas.com/kb/32/634.html&lt;/A&gt; &lt;BR /&gt;&lt;BR /&gt;Cynthia</description>
      <pubDate>Sun, 14 Oct 2018 13:58:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-have-a-SAS-Stored-Process-return-a-csv/m-p/504092#M134855</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2018-10-14T13:58:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to have a SAS Stored Process return a csv</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-have-a-SAS-Stored-Process-return-a-csv/m-p/504107#M134862</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas&lt;/a&gt;,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Thank you. In the example&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Sample for downloading a CSV file. */

data _null_;
   rc=stpsrv_header('Content-type','application/vnd.ms-excel');
   rc=stpsrv_header('Content-disposition','attachment; filename=temp.csv');
run;

ods csv file=_webout;
                                                                                                                                                                                                       
proc print data=sashelp.class; 
run;

ods csv close;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp; In the above example, let us assume my stored process's output is the Class data set. Should it be saved as a file ?&amp;nbsp; Which part of the above code actually takes the data set and exports as csv ? The data step does not identify the data source for the file to be exported while the print step would only print to the log, so I am kind of confused as to which step is actually specifying the data source for the response.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&amp;nbsp;&lt;/P&gt;&lt;P&gt;Uday&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Oct 2018 16:46:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-have-a-SAS-Stored-Process-return-a-csv/m-p/504107#M134862</guid>
      <dc:creator>UdayGuntupalli</dc:creator>
      <dc:date>2018-10-14T16:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to have a SAS Stored Process return a csv</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-have-a-SAS-Stored-Process-return-a-csv/m-p/504112#M134866</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/27543"&gt;@UdayGuntupalli&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas&lt;/a&gt;,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Thank you. In the example&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Sample for downloading a CSV file. */

data _null_;
   rc=stpsrv_header('Content-type','application/vnd.ms-excel');
   rc=stpsrv_header('Content-disposition','attachment; filename=temp.csv');
run;

ods csv file=_webout;
                                                                                                                                                                                                       
proc print data=sashelp.class; 
run;

ods csv close;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp; In the above example, let us assume my stored process's output is the Class data set. Should it be saved as a file ?&amp;nbsp; Which part of the above code actually takes the data set and exports as csv ? The data step does not identify the data source for the file to be exported while the print step would only print to the log, so I am kind of confused as to which step is actually specifying the data source for the response.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Uday&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That code is use the CSV ods destination to write to the _WEBOUT fileref.&amp;nbsp; &amp;nbsp;So the PROC PRINT results will be converted to CSV format and written to _WEBOUT.&amp;nbsp; If the rest of the Stored Process setup is correct the whatever is written to _WEBOUT is what is returned to the caller.&lt;/P&gt;</description>
      <pubDate>Sun, 14 Oct 2018 17:34:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-have-a-SAS-Stored-Process-return-a-csv/m-p/504112#M134866</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-10-14T17:34:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to have a SAS Stored Process return a csv</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-have-a-SAS-Stored-Process-return-a-csv/m-p/504128#M134870</link>
      <description>&lt;P&gt;Hi:&lt;BR /&gt;&amp;nbsp; The PROC PRINT does NOT only print to the LOG. The ODS CSV destination is writing to "_webout", which is the stored process "pipeline" from the requesting browser or client application to the application server.&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; Notice in the Stpsrv_header function calls the fact that the requesting browser should open vnd.ms-excel when the stored process results come back down the _webout "pipeline".&lt;BR /&gt;&lt;BR /&gt;Also, there is a content-disposition change to indicate a preference for the filename to be called "temp.csv" -- however, in my experience sometimes, this name is NOT used when the _webout stream is opened.&lt;BR /&gt;&lt;BR /&gt;Note that you have to submit the stored process from a client application that would accept the results. For example, this is not a stored process that could be invoked from the SAS Add-in for Microsoft Office, such as Word or PowerPoint. However, it could be invoked from the SAS Portal or the Stored Process Web Application.&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; In the above example, the stored process output is NOT the class data set. It will be the Proc Report data, as output by PROC PRINT, written as comma separated value files. It will NOT be the same as an exported file from PROC EXPORT. &lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; For example -- consider these 2 output files from non-stored process code -- submitted in a SAS session:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="export_vs_ods.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/23999i97D1B749864DF9E5/image-size/large?v=v2&amp;amp;px=999" role="button" title="export_vs_ods.png" alt="export_vs_ods.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; The difference is that when you use ODS CSV and _webout, the results are "streamed" back to the requesting client application, which is usually a browser and which uses the content-type header to determine how the requesting client application will receive the output stream from the stored process.&lt;BR /&gt;&lt;BR /&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Sun, 14 Oct 2018 19:48:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-have-a-SAS-Stored-Process-return-a-csv/m-p/504128#M134870</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2018-10-14T19:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to have a SAS Stored Process return a csv</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-have-a-SAS-Stored-Process-return-a-csv/m-p/504342#M134949</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas&lt;/a&gt;&amp;nbsp;&amp;amp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;,&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;While creating the stored process, I definitely ensured that "Stored Process Macros" was unchecked under the Include Code for option. However, I receive this error both for my own stored process and another test one we created for exporting "Class" dataset.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="10-15-2018 7-36-52 AM.jpg" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/24014i95101A46FB498A67/image-size/large?v=v2&amp;amp;px=999" role="button" title="10-15-2018 7-36-52 AM.jpg" alt="10-15-2018 7-36-52 AM.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Oct 2018 14:39:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-have-a-SAS-Stored-Process-return-a-csv/m-p/504342#M134949</guid>
      <dc:creator>UdayGuntupalli</dc:creator>
      <dc:date>2018-10-15T14:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to have a SAS Stored Process return a csv</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-have-a-SAS-Stored-Process-return-a-csv/m-p/504343#M134950</link>
      <description>Hi:&lt;BR /&gt;  That's not enough of the log to tell anything. I'd recommend working with Tech Support. How you created, registered and run the stored process makes a difference. For example, what was your client application? Did you use the Stored Process Web App? The message about no logical assign for filename _WEBOUT usually means that you registered the stored process incorrectly and did not indicate that it would produce streaming results, as described here: &lt;A href="http://support.sas.com/kb/34/120.html" target="_blank"&gt;http://support.sas.com/kb/34/120.html&lt;/A&gt; &lt;BR /&gt;&lt;BR /&gt;That's why I recommend working with Tech Support. Posting 2 lines of Log isn't going to give anyone the true picture of how you defined and ran the stored process.&lt;BR /&gt;&lt;BR /&gt;Cynthia</description>
      <pubDate>Mon, 15 Oct 2018 14:43:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-have-a-SAS-Stored-Process-return-a-csv/m-p/504343#M134950</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2018-10-15T14:43:00Z</dc:date>
    </item>
  </channel>
</rss>

