Date: Fri, 26 Jul 2002 17:04:30 -0400
Reply-To: Ian Whitlock <WHITLOI1@WESTAT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ian Whitlock <WHITLOI1@WESTAT.COM>
Subject: Re: Labeling columns names through macros
Content-Type: text/plain; charset="iso-8859-1"
Subject: Labeling columns names through macros
Summary: Example code
Respondent: IanWhitlock@westat.com
In part, Witness [bmeyer67@CALVIN.EDU] wrote:
> First, I'll do as Ian Whitlock requested.
>
> 1) Description of the problem.
>
> I want to assign descriptions taken from a table to the
> columns of another table. The relation between the two tables is
> such that the descriptions table contains an identifier, MType,
> that appears in the name of the other table in the format
> Count[MType Value]. The number of columns in the second table is
> unknown.
First, thanks for the subject line. However, I specified giving
sample data to help understand the problem. I will try to fill in
your absence.
Suppose we have data sets W and C. For example,
data w ;
retain count1 count3 count5 1 ;
run ;
data c ;
input mtype description $ ;
cards ;
1 abc
1 def
2 ghi
3 jkl
3 mno
4 pqr
5 stu
5 wxy
5 zzz
;
I want to label the variables beginning with the word "COUNT" where
the suffix determines a list of descriptions in C. For example,
COUNT5 should get the label "stu wxy zzz". How can I assign the
labels when I do not know which values of MTYPE will be used in the
names of the DATA set W ahead of time?
This isn't code to create the labels, but it indicates a method, and
you should have little trouble converting it to your task.
data control ( keep = mtype list ) ;
length list $ 40 ;
retain list ;
set c ;
by mtype ;
if first.mtype then list = " " ;
list = trim(list) || " " || description ;
if last.mtype ;
list = left(list) ;
run ;
data _null_ ;
if _n_ = 1 then set w ( keep = count: obs = 1 ) ;
array v (*) count: ;
set control ;
do i = 1 to dim ( v ) ;
if substr(vname(v(i)),6) = compress(put(mtype,3.)) then
put "label: count" mtype "=" list ;
end ;
run ;
IanWhitlock@westat.com