The SAS Output Delivery System and reporting techniques

Customizing output file names

Not applicable
Posts: 0

Customizing output file names

Hi all --
Here's my problem: I have written a program that is going to be invoked through an html front-end. Meaning, end users will put in their parameters through an html front-end and the program will use those user-defined parameters to generate a customized report. Now, I have to write a section of the code that will output an xls file in the following format "projectname_userID_currentdate_currenttime.xls" My question is: what do I do so that each user has a report generated with his own userID. This is going to be a macro code, but not sure how to go about doing it. I know i will have to define the userid in a separate parameter file, which also includes the other parameters that the program uses. Not sure if I am making myself understood. If somebody can help me with this, it'll be awesome.

Posts: 9,366

Re: Customizing output file names

Posted in reply to deleted_user
If you have macro variables as shown below, then you can build your filename, as shown by the FNAME macro variable (you should be able to submit this code and program and then review the SAS log to see how the &FNAME macro variable was used):

%let pjname = Wombat_;
%let userid = Dorothy_;
%let cdate = %sysfunc(today(),date9.)_;
%let ttime = %sysfunc(time(),time.); /* might not allow : in file names */
%let ctime = %sysfunc(translate(&ttime,_,Smiley Happy); /* translate function gets rid of : */

%let fname = &pjname.&userid.&cdate.&ctime..xls;

%put ----------> The macro variables;
%put pjname= &pjname;
%put userid= &userid;
%put cdate= &cdate;
%put ttime= &ttime;
%put ctime= &ctime;
%put fname = &fname;

If you are going to submit the program, via SAS/IntrNet or the SAS Stored Process Web Application, for example, you can send the SAS macro parameters as HTML name/value pairs like this:



(FYI: The URL and Program name for the SAS Stored Process Web Application would be different than what is shown above.) If you were going to set the CDATE and CTIME name/value pairs in your HTML form using JavaScript, then you would add them as hidden parameters, too. Otherwise, you'd have to set them inside your SAS program, when it was first invoked, before your reference to the &FNAME macro variable.

If you are NOT using SAS/IntrNet to invoke the SAS program, or if you're using the SAS Stored Process Web Application or you're using some other method to invoke the program, then your best bet for getting the correct answer to this question is to contact Tech Support, since it is NOT really an ODS or BASE reporting procedure question.

Not applicable
Posts: 0

Re: Customizing output file names

Posted in reply to Cynthia_sas
Hi Cynthia,
Here's a sample code I wrote.

%let userid = abcd; /* I want to link this to an external txt file that will only have a userid. So that whenever that userid changes, it will automatically change the userid in this %let statement and, subsequently, change the userid in the ods html file statement below. All I want to find out is a way to link the above %let staetment to an external file */

data name;
33 56000
46 60000
ods html file = "/home/e026976/test/&userid..xls";
proc print data=name;
ods close;

thanks for your help. These small titbits are really helping me expand my SAS knowledge.
-- Einnor
Super Contributor
Posts: 260

Re: Customizing output file names

Posted in reply to deleted_user
What you need to do is generate the USERID macro-variable through a Data step rather than a %LET statement.
This will look like :

INFILE "your external file" MISSOVER ;
INPUT login :$30. ; /* login is read on at most 30 characters */
CALL SYMPUT("userid", login) ;

Then you can use the &userid reference in every other statement, including your ODS file name.

Not applicable
Posts: 0

Re: Customizing output file names

This has WORKED !!!!!! I'd like to thank everyone here for making SAS all fun Smiley Happy The more I do, the more I get hooked on SAS Smiley Happy

Not applicable
Posts: 0

Re: Customizing output file names

Posted in reply to deleted_user
Date and time can be generated very easily from SAS functions and formats.
The right user ID may be a little more difficult. Although the SAS session has a "userID" stored in an automatic macro variable &sysUserID, that will probably be different from the identity of the user at the browser.
I assume each user at a browser will have signed into your system in some way, with a userID that will be stored in the whole environment - somewhere - probably as a macro variable, and possibly as an environment variable. The first is easier to discover. In developing your solution, place this code inside a test SAS program you invoke through the browser : [pre] %put _all_; [/pre] You may need to invoke the program wiith one of the _debug_ options that responds with the SAS log. On that SAS log you should see the name of a macro variable whose value is your userID to the browser application.
Given that name, say &app_user, you can construct a file name like [pre] %let datetimes = %sysfunc( datetime(), IS8601DT) ;
%let name = reportX_for&app_user._at_&datetimes..xls ; [/pre]
If the : generated by the IS8601DT datetime format cause invalid filename problems, either compress out the : symbol with: [pre] %let datetimes =%sysfunc( compress( &datetimes, : )); [/pre]or build a datetime picture format that suits your need better, see for details of the date and time features you can use to build your preferred picture format.

Good Luck

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