Date: Fri, 9 May 2003 09:46:55 -0400
Reply-To: Quentin McMullen <Quentin_McMullen@BROWN.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Quentin McMullen <Quentin_McMullen@BROWN.EDU>
Subject: Re: Retaining variable label in a dataset
Content-Type: text/plain; charset="iso-8859-1"
Richard A. DeVenezia wrote:
> "Steve Jones" <firstname.lastname@example.org> wrote in message
> > Hi everyone,
> > I was wonedering if there is a way to keep or
> > 'transfer' the label of a particular variable
> > to another one in a dataset.
> There are only functions for getting variable information at run-time.
> (Search help for "SAS FUNCTIONS: Variable Information Functions")
> There are no functions to set [what I see as] the 'settable' aspects
> (label, format, informat) of a data step pdv variable at run-time.
> Thus you need two steps, one to get the label and another to set the
> data a;
> attrib xyz label = 'Number of Goals';
> xyz = 1;
> data b;
> set a;
> abc = log(xyz);
> if _n_ = 1 then
> call symput ('abcLabel', vlabel (xyz));
> proc datasets nolist lib=work;
> modify b;
> label abc = "&abcLabel";
If you really wanted to do it in one step, you could do it with a "macro
function". The below quick 'n dirty macro is horribly slow because it
requires creation of sashelp.vcolumn in order to get the variable label.
So, probably not a reasonable solution, but thought I'd send it anyway....
%macro GetVarLabel(data= /*accepts only 1-level name*/
%local dsid rc VarLabel;
%let dsid = %sysfunc ( open ( sashelp.vcolumn
) ) ;
%if &dsid=0 %then %put ER%str()ROR: USER dsid=&dsid;
%if &rc ne 0 %then %put ER%str()ROR: USER rc=&rc;
%let VarLabel =%sysfunc(getvarc(&dsid,%sysfunc(varnum(&dsid,label))));
%let dsid = %sysfunc ( close(&dsid) ) ;
x="Label for X"
y="Label for Y"
proc contents data=b;
And after I wrote this, I realized that Roland had probably included this in
his bag of macros. And indeed he has. See %VarLabel at
http://www.datasavantconsulting.com/roland/sasautos.html . Looks much
better than what I just wrote, as it avoids sashelp.vcolumns...