Date: Fri, 18 Oct 1996 17:48:00 -0400
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
Subject: Re: Here's a handy (macro) thingy...
New Text Item: Here's a handy (macro) thingy...
Someone once said "If you can't do something at least 3 different ways
in SAS then you haven't read all the manuals". To which I might add,
"If you have read all the SAS manual, you need a life". (^^; But you
might want to check out "Macro Facility Enhancements for Release 6.11"
in the SUGI '95 Proceedings. It demonstrates a different approach to
The code for your example would be:
%let i = %sysfunc(putn(&i,z5.));
The function "%sysfunc" works in open code with most SCL functions.
It can be used for lots of cool stuff; like putting a time stamp in a
title showing the exact time that a report was run. That is:
Title2 "This report was run at %sysfunc(time(),time12.2)";
Of course the function resolves when the title line executes, not when
the SAS job is submitted which is the value in &systime.
______________________________ Reply Separator _________________________________
Subject: Here's a handy (macro) thingy...
Author: lfleming@ACTRIX.GEN.NZ@INTERNET at RDNOTES
Date: 10/18/96 11:12 AM
(Embedded image moved to file: PIC001.PCX)
Straight SAS code won't allow a '%if' command, because it has to
be placed inside a macro, whereas other macro commands can be
typed in directly (command line, between procs et al).
However, sometimes I have to do a conditional macro statement, and
here's one way of doing it. I commonly want to right-justify and
zero fill a pseudo-numeric macro value so I can do valid comparisons
with other values. Assume a value in 'i' of 53, and a required value
%let i = %substr(0000&i, %length(&i), 5);
The first parameter resolves to 000053, the second to 2 (the length
of the text value '53', and the result: 53. If i = 5, then the first
parameter is 00005, the second 1, and the result 00005.
It may not be that important, but if there were an obfuscated SAS
competition, this would be my one-liner. (-8
Laurie Fleming | What do you get when you | (+64 4) 479-1589
4 Kenya St | cross Lee Iacocca and a | (+64 21) 688-140
Ngaio | vampire? | email@example.com
Wellington 6004 | | firstname.lastname@example.org
New Zealand | Autoexec bat. |