Date: Mon, 19 May 1997 18:36:53 -0800
Reply-To: Jack Hamilton <Jack_Hamilton@HCCOMPARE.COM>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Jack Hamilton <Jack_Hamilton@HCCOMPARE.COM>
Organization: HealthCare COMPARE Corporation
Subject: Re: SUGGESTION: Data step code in formats
Content-Type: text/plain; charset=us-ascii
John Whittington <johnw@MAG-NET.CO.UK> wrote:
> Jack, I'm glad to see it's someone other than me 're-designing SAS' this
> time - you can take the flak for a change!
I prefer to think of it as "extending".
> When do you exactly see that code being executed - presumably repeatedly for
> each data value?
Yes. The usage would be, for example,
proc codedformat; /* I changed this a little bit */
invalue nlvmnm. (invalue=invalue outvalue=outvalue upcase);
newvalue = translate(invalue, ":", ".");
if index(newvalue, "VM") > 0 then
newvalue = tranwrd(newvalue, "VM", "AM");
else
newvalue = tranwrd(newvalue, "NM", "PM");
outvalue = input(newvalue, time.);
run;
quit;
data test;
format mytime time.;
infile cards;
input @1 mytime nlvmnm7. ;
cards;
12.01vm
12.02nm
;;;; run;
instead of
data test;
format mytime time.;
infile cards;
input @1 testtime time5.
@6 testvmnm $char2.;
testtime = translate(testtime, '.', ':');
mytime = input(testtime, time5.);
select upcase(testvm);
when "VM" /* morning */
; /* Don't need to do anything. "
when "NM"
mytime = mytime + '12:00't;
otherwise
error 'Invalid time';
end select;
cards;
12.01vm
12.02nm
;;;; run;
My proposed way doesn't require many more lines than the current way
if you're only going to use the format once, and many fewer lines if
you're going to use it in several data steps. It's more obvious what
the main code is doing, and it's easier to share code with naive
users. A user-written format could also be used in SQL, ASSIST,
and other GUI places more easily than the data step code can.
> Are you sure that you aren't close to re-inventing
> (arrrghhh - once was {more than} enough!) the SAS macro language?
It's really the data step language, rather than the macro language.
(And I also wish they'd come up with a replacement for the macro
language.)
> The functionality you propose would certainly be very welcome. Although we
> can obvioulsy create formats using the CNTLIN method - they are really only
> 'look-up tables'. There is, as you say, no way to write a format that will
> actually 'compute on the fly' - in the way that one imagines many intrinsic
> SAS (in)formats do.
-----------------------------
Jack_Hamilton@HCCompare.com
HealthCare COMPARE Corp.
West Sacramento, CA