Date: Tue, 20 May 2008 11:55:17 -0400
Reply-To: Andrew Hansen <hansen.andrew.e@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Andrew Hansen <hansen.andrew.e@GMAIL.COM>
Subject: Re: Assign a new variable the label from an existing variable
Not sure if it would be the most efficient, but you could use a macro like
this...
%macro get_label(dsin,varname);
%local label;
%let dsid=%sysfunc(open(%str(&dsin)));
%if &dsid gt 0 %then %do;
%let LABEL =%bquote(%sysfunc(varlabel(&dsid,%sysfunc(varnum
(&dsid,&varname)))));
%let rc=%sysfunc(close(&dsid));
%end;
&label
%mend;
It would be used as follows...
data work.need;
set work.have;
County_d = put(county,$county.);
attrib country_d label= "%get_label(work.have,country)";
run;
On Tue, 20 May 2008 10:02:35 -0400, Jack Clark <JClark@CHPDM.UMBC.EDU>
wrote:
>Hello,
>
>
>
>I'm hoping to get suggestions from the list on the best way to assign a
>new variable the label from an existing variable. I am using SAS v8 on
>UNIX, but got similar error messages with V9.2 on Windows.
>
>
>
>I have a dataset of coded variables. For example, I have a variable
>called COUNTY which is the 2-digit county code. The variable has a
>label - "County". I need to create a new variable (COUNTY_D) which is
>the formatted version of county, but I want it to have the same label as
>the coded variable COUNTY.
>
>
>
>I was hoping that the VLABEL function could help, but either I am not
>using it properly or it is not allowed in this context. Any suggestions
>are appreciated.
>
>
>
>
>
>Data need;
>
> Set have;
>
>County_d = put(county,$county.);
>
>Attrib county_d label = vlabel(county);
>
>Run;
>
>
>
>From the log:
>
>6 county_d = put(county,$county.);
>
>7 attrib county_d label = vlabel(county);
>
> -
>
> 22
>
> 76
>
>ERROR 22-322: Syntax error, expecting one of the following: a name, -,
>:, FORMAT, INFORMAT,
>
> LABEL, LABLE, LENGTH, _ALL_, _CHARACTER_, _CHAR_,
>_NUMERIC_.
>
>
>
>ERROR 76-322: Syntax error, statement will be ignored.
>
>
>
>
>
>
>
>Jack Clark
>
>Research Analyst
>
>Center for Health Program Development and Management
>
>University of Maryland, Baltimore County
>
>
|