BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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.

Thanks
Einnor
5 REPLIES 5
Cynthia_sas
SAS Super FREQ
Einnor:
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):
[pre]

%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,_,:)); /* 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;
[/pre]

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:
[pre]

action="/cgi-bin8/broker.exe">





[/pre]

(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.

cynthia
deleted_user
Not applicable
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;
datalines;
33 56000
46 60000
;
run;
ods html file = "/home/e026976/test/&userid..xls";
proc print data=name;
run;
ods close;



thanks for your help. These small titbits are really helping me expand my SAS knowledge.
-- Einnor
Olivier
Pyrite | Level 9
What you need to do is generate the USERID macro-variable through a Data step rather than a %LET statement.
This will look like :

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

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

Regards,
Olivier
deleted_user
Not applicable
Hi,
This has WORKED !!!!!! I'd like to thank everyone here for making SAS all fun 🙂 The more I do, the more I get hooked on SAS 🙂

Thanks,
Einnor
deleted_user
Not applicable
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 http://support.sas.com/onlinedoc/913/getDoc/en/proc.hlp/a002473467.htm#a000530223 for details of the date and time features you can use to build your preferred picture format.

Good Luck

PeterC

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 660 views
  • 0 likes
  • 3 in conversation