BookmarkSubscribeRSS Feed
michael_friendly
Fluorite | Level 6

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

sascgi

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, getlist1.sas which is run under control of sascgi.

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

title 'getlist.sas';

/*

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/select.sas';

%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;

%select(

    out=sample,

    outstat=stats,

    items=&items,

    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),

    print=NO

    );

   

%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>";

%mend;

%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>";

%mend;

%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>";

%mend;

data _null_;

    file STDOUT;

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

    put "<table>";

    %var;

    %min;

    %max;

    put "</table>";

    run;

   

%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>";

    run;

   

*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>";

   run;

proc print data=stats label;

    id _label_;

    var mean std min max;

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

    run;

ods html close;

/*

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

proc export data=sample

    outfile="&sasfilename..csv"

    dbms=csv;

    run;

*/

5 REPLIES 5
Doc_Duke
Rhodochrosite | Level 12

Michael,

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

Duke

michael_friendly
Fluorite | Level 6

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.

Doc_Duke
Rhodochrosite | Level 12

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

michael_friendly
Fluorite | Level 6

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.

--- export-test.sas ---

proc export data=sasuser.class

    outfile="class.csv"

    dbms=csv;

run;

-Michael

Ksharp
Super User

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

proc export data=sample

    outfile="&sasfilename..csv"

    dbms=csv replace ;

    run;

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.

Ksharp

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1421 views
  • 0 likes
  • 3 in conversation