Search
Monday, December 01, 2008 ..:: Technical » SAS Tips ::.. Register  Login
 Useful SAS Programming Tips Minimize
Creating a macro variable with a datetime stamp. - Tuesday, October 30, 2007

Create a macro variable with a datetime stamp.  (I've used this in the next SAS tip by adding the datetime stamp to SAS log file to avoid overwriting a previously created SAS log file.) 

 %let datetimestamp = %sysfunc(date(),date9.)-%left(%sysfunc(time(),hhmm2.)):%substr(%sysfunc(time(),hhmm5.),4);

%put &datetimestamp;

 

Create a datetime stamped SAS log file. - Tuesday, October 30, 2007

To create a separate datetime stamped SAS log file for each time a program is run, place the following code at the top of the program (this uses the datetime stamp macro variable from the precious SAS tip):

* At the start of the code to log;

proc printto log="logs\XYZ System Report run &timestamp..log";
run;

* At the end of the code to log;

proc printto log=log;
run; 


SAS Macro to print a message warning of an past or future event - Wednesday, May 30, 2007

I recently had a need  for a program to work out the number of days, weeks etc before a particular event.  (Kind of like the countdown to Christmas or something like that.) So I thought of writing a macro to accept a date parameter and a message parameter to write a semi-customised message of the form " nn Days, nn hours and nn minutes to xyz event".  If you think this might be of use, feel free to download the macro and extend it if you want.

 read more ...

Changing the default prompt on login from SAS/Connect - Wednesday, January 24, 2007
The standard SAS/Connect script prompts for a user login and password with a window headed 'TYPE WINDOW'.  You can change this to a more meaningful prompt using the following code snippet.

%let cstitle = 'Login to YourHostName';

(Taken from an old SAS-l posting.  At least it was the earliest reference I could find)
 read more ...

Creating a Pound Sterling format. - Wednesday, January 24, 2007
There are two ways of displaying currency values with a pound symbol:
  1. Use PROC FORMAT with the PICTURE option:
             proc format lib=library;
             picture low-high '000,000,000,009.99' prefix='£ ';
             run;

     2. Use the following option to modify the EUROfmt options.

             options debug='EURO=A3';
            * the default Euro hex char is 80, A3 is the UK pound symbol;

             data  _null_;
               value = 1234.56;
               put value euro10.2;
             run;

            Will display: £1234.56 in the SAS log in a character set.  (Not sure whether this would work on a US character set?)
 
 

Using the SAS URL filename statement to 'screen scrape' the web. - Friday, March 11, 2005 - Friday, March 11, 2005

The following link is for a bit of SAS code demonstrating the INPUT @'text' syntax.

 read more ...

Revised : Macro to write SAS Dataset Contents to Excel - Friday, September 10, 2004 - Friday, September 10, 2004

This macro will write a PROC CONTENTS of a SAS Dataset to Excel. UPDATED 10th September 2004 : I realised I'd posted the wrong version of this program, so here is a better version !

 read more ...

Example of new 'Regular Expression' functions. - Sunday, August 15, 2004 - Friday, September 10, 2004

The SAS code stub attached is a practical example of regular expressions, identifying the existence of datetime stamp in a character string of the form YYYY-MM-DD:HH-MM-SS. As the comment s in the code suggest this was used to identify a datetime stamp in a filename used in an ETL (Extract/Transform/Load) process of a data warehouse build. I'm sure there are plenty more sophisticated ways of using regular expressions, but this is one case where I was able to find an obvious benefit over standard SAS functions.

 read more ...

Some Useful UNIX commands for SAS users. - Tuesday, August 17, 2004 - Tuesday, August 17, 2004

This document is a useful subset of UNIX commands for SAS users.

 read more ...

Reuse an existing Netscape session on Unix - Tuesday, August 17, 2004

Do you have a SAS application under Unix, generating HTML files? And are your users getting impatient when they have to wait 15 seconds or more when a SAS WBROWSE command starts up a new Netscape session to show the results?

Here's a way to reuse an existing Netscape session. The trick is not to use the WBROWSE command, but send Netscape commands to Unix using the SYSTEM command!

The Unix Netscape commands to start a new session and to reuse an existing session for a new destination are:

netscape protocol:// &
netscape -remote 'openURL(other-URL)' &

In SAS you use these commands like this. Start a session with:

rc=system('netscape http://www.sas.com &');

Reuse a session with

rc=system("netscape -remote 'openURL(www.webminer.co.uk)' &");

 read more ...

Philip Mason's SAS Tips - Wednesday, June 09, 2004

Philip Mason, of Wood Street Consultants is one of the foremost SAS Consultants working in the UK. This link points to his SAS Tips page.

 read more ...

Submitting JCL directly from a SAS Job (not for the fainthearted !) - Tuesday, August 17, 2004

You can use SAS to output JCL directly to the job stream using the following syntax:

filename jes sysout=a pgm=intrdr recfm=f lrecl=80;

data _null_;
 file jes;
 file "//JOBCARD JOB ,'YOUR NAME',";
 file "// TIME=NOLIMIT";
 file "//STEP01 EXEC SAS,HOLD=YES,OUT=*,OPTIONS='S=0'";
 file "//WORK DD UNIT=(SYSDA,4),SPACE=(27648,65000,30000),,,ROUND)";
 file "//SYSIN DD *";
 file "data _null_;";
 file "put 'Hello World';";
 file "run;";
run;

Note: Please note that the Job Card syntax is very site dependent and the above JCL is meant as an example rather than working code. Also, many sites will have restricted access to the 'internal reader' using RACF or ACF2. So if you really need to do this you may need to request changes to your (or your batch processes) security settings.  

Using the FTP Filename engine to read remote data WITHOUT SAS/Connect. - Tuesday, August 17, 2004

You can use the FTP engine to remotely access external files without SAS/Connect. Here's an example showing accessing a mainframe file and prompting for a user password :

filename remote ftp "'username.sample.data'" HOST='ip-address' user='username' prompt;

data _null_;
  infile remote;
  put _infile_;
run;

Note : The single quotes contained within the double quotes (!?) are needed to ensure that the correct MVS filename is used. When the single quotes are left out, the FTP engine adds the current username as a prefix to the filename quoted. 

Neat Way to create Excel files from ODS : Updated 19/6/2003 - Tuesday, August 17, 2004

If you specify ODS HTML and give the output filename an extension of .xls, Excel automatically interprets your ODS output as an Excel file - no import required. Is there a downside to this ?

Update: Apparently, this method creates large files (dependant on the ODS style used.) A workaround is to use style=minimal. The output isn't pretty, but the Excel file is smaller.

Code Stub:

ods html body="c:\dir\subdir\ODS Report.xls" style=minimal;

proc print data=sasuser.class;
run;

ods html close;
 


Syndicate   Print   
 Users Online Minimize
People Online People Online:
Visitors Visitors: 5
Members Members: 0
Total Total: 5

Online Now Online Now:

 Print   
Copyright 2005-2008 WebMiner Ltd.   Terms Of Use  Privacy Statement
DotNetNuke® is copyright 2002-2008 by DotNetNuke Corporation