Date: Fri, 28 May 1999 14:38:39 -0400
Reply-To: jiwanisz@QCHN.QUINTILES.COM
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: John Iwaniszek <jiwanisz@QCHN.QUINTILES.COM>
Subject: Re: SASTip: ATTRIB allows association and repetition
Content-type: text/plain; charset=us-ascii
I agree with you regarding extending and simplifying attrib. I wrote a macro
that does a lot of what you are suggesting (I included the macro definition
below). It can be even be used to input from flat file. I did not include the
whole macro because it is tremendously sloppy and I don't feel like suffering
the slings and arrows this afternoon. Note the most frequent parameters are
list style while the less frequent ones are named. I have found this to be a
useful mnemonic when writing macros of this type.
%macro attr( varname, leng, label, format=, informat=, drop=n, retain=n,
rinit=%str(), putfrom=, inptfrm=, input=n, atcol=, lastin=n);
John
"Karsten M. Self" <kmself@IX.NETCOM.COM> on 05/28/99 02:26:54 PM
Please respond to "Karsten M. Self" <kmself@IX.NETCOM.COM>
To: SAS-L@LISTSERV.VT.EDU
cc: (bcc: John Iwaniszek/QCHN/Quintiles)
Subject: Re: SASTip: ATTRIB allows association and
repetition
Hudson, Spencer wrote:
>
> Interesting, the method also works for overlapping groups and for name
> range lists based on position in the PDV:
Right. The gist of my comment was that a variable could appear multiple
times, whether implicitly (listed) or explicitly (enumerated) mentioned
in the ATTRIB statement, and that the _last_ appearance for a _specific_
attribute (length, label, format, informat) would take precedence.
I'll repeat again my periodic gripe that the ATTRIB statement should be
extended to a general variable declaration statement covering such
attributes such as DROP, KEEP, and RETAIN as well.
Ability to specify legal/illegal value rules would be an added plus --
this would allow specification of, e.g. business rules, directly in
program code. Not necessarily the best practice (I prefer independent
verification tables, an OO approach might be better), but not without
its uses either.
Finally, a shortened syntax would be nice. Unfortunatly 'length' and
'label' (and my proposed 'legal') preclude single-character
abbreviations.
Example illustrating concepts:
attrib
myvar len= $1 fmt= $1. lab= 'Sample boolean var' keep retain
legal=('1','0')
weekday len= 3 fmt= 1. lab= 'Day of week number' keep
legal=(1,7,1) /* list 1 to 7 by 1 */
qrptmon len= 3 fmt= 1. lab= 'Quarterly report months' keep
legal=(3,12,3) /* list 3 to 12 by 3 */
denom len= 8 fmt= best. lab= 'Denominator' keep
illegal=((<= .Z), 0) /* no divide by zero or missing */
;
...attempts to populate a variable with an illegal value would
> data _data_;
> retain a b c d e f g h i j k l m n o p q r s t u v w x y z ;
> attrib
> a -- k label= "First group"
> g -- q label= "Second group"
> a -- z length= 7
> d -- f length= 6
> k label= "Changed my mind"
> m length= 3
> ;
>
> run;
>
> proc contents data= _last_;
> run;
> ________________________________________________________________________
> _______________________
>
> Spencer Hudson
> ViroPharma Incorporated
> 405 Eagleview Boulevard
> Exton, PA 19341
>
> Telephone 610 458 7300 extension 154
> FAX 610 458 7380
> Electronic Mail shudson@viropharma.com
> Web www.viropharma.com
> Ticker VPHM (NASDAQ)
>
> -----Original Message-----
> From: Karsten M. Self [mailto:kmself@IX.NETCOM.COM]
> Sent: Thursday, May 27, 1999 6:01 PM
> Subject: SASTip: ATTRIB allows association and
> repetition
>
> I'm working with some long lists of variables my client
> would like to
> have labled and formatted. I say to myself, "Self,
> wouldn't it be nice
> to be able to group vars one way for labeling and
> another for
> formatting?". Whad'ya know? Not much, you?
> (http://www.notmuch.com/).
>
> Turns out you can specify groups of variables in an
> ATTRIB statement,
> you can specify groups of variables multiple times, and
> the last listed
> value for an option is applied. Note that the label for
> X20 and the
> length for X3 are taken from the _last_ occurance of
> each of these
> variables.
>
> This doesn't make your code any prettier, but it does
> make dealing with
> long lists of variable attributes somewhat easier.
>
> data _data_;
> attrib
> x1-x10 label= "First group"
> x11-x20 label= "Second group"
> x1-x4 length= 7
> x5-x8 length= 6
> x9-x12 length= 5
> x13-x16 length= 4
> x17-x20 length= 3
> x20 label= "Changed my mind"
> x3 length= 3
> ;
> retain x1-x30 .;
> run;
>
> proc contents data= _last_;
> run;
>
> --
> Karsten M. Self (kmself@ix.netcom.com)
>
> What part of "Gestalt" don't you understand?
> Welchen Teil von "Gestalt" verstehen Sie nicht?
>
> Web: http://www.netcom.com/~kmself/
> SAS for Linux:
> http://www.netcom.com/~kmself/SAS/SAS4Linux.html
--
Karsten M. Self (kmself@ix.netcom.com)
What part of "Gestalt" don't you understand?
Welchen Teil von "Gestalt" verstehen Sie nicht?
Web: http://www.netcom.com/~kmself/
SAS for Linux: http://www.netcom.com/~kmself/SAS/SAS4Linux.html