Help using Base SAS procedures

proc export doesn't work in a cgi application

Posts: 24

proc export doesn't work in a cgi application

I have a legacy web application run by my sascgi script,


The application, Word List Generator, runs a SAS program, taking input from variables placed in the

environment, and writing results back to the browser via STDOUT.

I recently tried to update this to also write a .csv file to the /www/tmp directory using PROC EXPORT.

However, SAS seems to hang at the point that PROC EXPORT is invoked in my program.

That is, when I run the script in debug mode, I can see output up to the point where

PROC EXPORT is called, but then nothing --- and no errors in the SAS .log file.

As a work-around, I can get what I want using an old %sas2csv macro, but I'm curious why

PROC EXPORT fails here.

FWIW, below is the SAS program, which is run under control of sascgi.

The PROC EXPORT step is now commented out at the end.

title '';


This program gets HTML form input passed via the environment from sascgi.

  It selects random word list(s) as specified by these parameters,

  and formats it (via the htmltab macro), printing results to STDOUT.

  This is intended as a demonstration of the sascgi protocol, but may

  be useful in its own right.


%global nobs;

%include '/home/friendly/sasuser/pools/';

%let tmp=/tmp; *--relative to server root;

%let sasfilename = %sysget(SASFILENAME);

%let items = %sysget(ITEMS);

%let lists = %sysget(LISTS);

%put SASFILENAME: &sasfilename;

%put ITEMS: &items;

%put LISTS: &lists;






    let_min=%sysget(LET_MIN),    let_max=%sysget(LET_MAX),

    syl_min=%sysget(SYL_MIN),    syl_max=%sysget(SYL_MAX),

    freq_min=%sysget(FREQ_MIN),    freq_max=%sysget(FREQ_MAX),

    imag_min=%sysget(IMAG_MIN),    imag_max=%sysget(IMAG_MAX),

    conc_min=%sysget(CONC_MIN),    conc_max=%sysget(CONC_MAX),

    mean_min=%sysget(MEAN_MIN),    mean_max=%sysget(MEAN_MAX),




%put NOBS = &nobs were selected in %sysget(LISTS) lists;

%macro var;

    put "  <tr>";

    put "    <th>Variable</th>";

    put "    <th>K-F Word frequency</th>";

    put "    <th>Imagery</th>";

    put "    <th>Concreteness</th>";

    put "    <th>Meaningfulness</th>";

    put "    <th># Syllables</th>";

    put "    <th># Letters</th>";

    put "  </tr>";


%macro min;

    put "  <tr>";

    put "    <th>Minimum</th>";

    put "    <td>%sysget(FREQ_MIN)</td>";

    put "    <td>%sysget(IMAG_MIN)</td>";

    put "    <td>%sysget(CONC_MIN)</td>";

    put "    <td>%sysget(MEAN_MIN)</td>";

    put "    <td>%sysget(SYL_MIN)</td>";

    put "    <td>%sysget(LET_MIN)</td>";

    put "  </tr>";


%macro max;

    put "  <tr>";

    put "    <th>Maximum</th>";

    put "    <td>%sysget(FREQ_MAX)</td>";

    put "    <td>%sysget(IMAG_MAX)</td>";

    put "    <td>%sysget(CONC_MAX)</td>";

    put "    <td>%sysget(MEAN_MAX)</td>";

    put "    <td>%sysget(LET_MAX)</td>";

    put "    <td>%sysget(SYL_MAX)</td>";

    put "  </tr>";


data _null_;

    file STDOUT;

    put "<h2>Selection parameters:</h2>";

    put "<table>";




    put "</table>";



%sas2csv(data=sample, out=&sasfilename..csv, quote=CHAR,

    keep=list word freq imag conc meaning syl let);

data _null_;

    file STDOUT;

    put "<h3>Download CSV file</h3>";

    put "<a href='&tmp/&sasfilename..csv'>Download CSV file containing your word lists</a>";



*ods listing close;

ods html body=stdout (no_bottom_matter no_top_matter) style=styles.default;

*ods html body='getlist1.html' style=styles.minimal;

proc print data=sample label;

   id list Word;

   by list;

   var freq imag conc meaning syl let;

   label word='Word' list='List';

   title "<h3>&lists lists of &items items selected from Paivio Word Pool</h3>";


proc print data=stats label;

    id _label_;

    var mean std min max;

   title "<h3>Summary statistics for all &lists list(s)</h3>";


ods html close;


*-- Also produce a .csv file, but proc export doesnt run under sascgi;

proc export data=sample





Trusted Advisor
Posts: 2,113

Re: proc export doesn't work in a cgi application


What version of SAS?  UNC naming support was spotty prior to 9.3; sometimes it worked and others it didn't.  The usage notes mostly refer to UNC names with spaces in them as being the root cause.

Doc Muhlbaier


Posts: 24

Re: proc export doesn't work in a cgi application

Sorry for omitting my environment:

Running SAS 9.2 (TS2M3) under Kubuntu 12.04 linux on my server

But I'm just using an ordinary path name in PROC EXPORT, of the form  outfile="&sasfilename..csv"

to write in the current directory, which is like /www/tmp, and is world-writable on my server.

Trusted Advisor
Posts: 2,113

Re: proc export doesn't work in a cgi application

The plot thickens.  Kubuntu is not a supported OS for SAS 9.2.

Posts: 24

Re: proc export doesn't work in a cgi application

Thanks for persisting, Doc

Hmm, this may be more serious than I thought, and I now think that this problem is

OS-related and specific to proc export; nothing to do with running this under a

cgi application.

In general, SAS 9.2 installs and runs under ubuntu or debian just as well as as under a supported linux distro.  At least is has in everything I've done up to now.

I tried running proc export directly as my normal user, and got the same behavior:

a 0-length log file, and no output.

--- ---

proc export data=sasuser.class





Super User
Posts: 9,671

Re: proc export doesn't work in a cgi application

Or you can try add an option REPLACE in proc export.

proc export data=sample


    dbms=csv replace ;


I also have some experience about this .When there is already a file with the same name, proc expand will shut down, But SAS will give you the information in LOG window, so I am curious that you got nothing of LOG information.


Ask a Question
Discussion stats
  • 5 replies
  • 3 in conversation