LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (June 2001, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 6 Jun 2001 16:53:19 +0100
Reply-To:     Peter Crawford <peter.crawford@DB.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Peter Crawford <peter.crawford@DB.COM>
Subject:      exchange labels with var names
Comments: To: dennis <dennis_grodsen@EKNO.COM>
Content-type: text/plain; charset=iso-8859-1

I really can't imagine why you would want a reversal, of names and labels (?) but don't you just want to use code something like proc datasets nolist library=your_lib ; modify your_dataset; label &labels ; rename &renames ; run; where &labels has structure like name1 = "label1" name2="&label2" ,,,,,,, and &renames has structure like oldname1 = newname1 oldname2 = newname2 ....

The rename and label lists are easily generated with proc sql like option _last_ = <your data set > ; proc sql noprint; select trim( name ) || '=' || quote( trim( name )) , trim( name ) || '=' || quote( trim( label))||'n' /* embedded blanks in label need "name constant"n notation */ into :labels separated by ' ' , :renames separated by ' ' from dictionary.columns where libname = "%scan( &syslast, 1, . )" and memname = "%upcase(%scan( &syslast, 2, . ))" order by varnum ; /* order is really not important */ quit;

option validvarname=any; /* needed for names with embedded blanks etc*/ proc datasets library=%scan( &syslast, 1, .) nolist; modify %upcase(%scan( &syslast, 2, . )); label &labels ; rename &names ; run; quit;; This works for a data set in my work library, except when the old label exceeds the 32 limit for long variable names You could find some solution to that, I'm sure !

good luck Peter Crawford

Datum: 06/06/2001 15:11 An: SAS-L@LISTSERV.UGA.EDU

Antwort an: dennis <dennis_grodsen@EKNO.COM>

Betreff: exchange labels with var names Nachrichtentext:

I would like to exhange the labels with the variable names in a data set.

I have tried to do this with a macro as follows but I am unable to go much further than this. The first part of the code reads the sashelp.vcolumn file and grabs the appropriate data and places it in another file. I know that some of this code is not necessary - but it is work in progress....

My problem is getting sas to read the new file and allocating for the max number of varnum, a rename statement calling up the values to be renamed. This code doesnt work but it may give you an idea of my thinking and working to date.... I should probably build in some error checking incase labels dont exist for all vars.

%macro renlabel(libs,mems); data dxg (keep=label name varnum); set sashelp.vcolumn; if libname="&libs" and memname="&mems"; run; proc sort data=dxg; by decending varnum; run; data _null_; set dxg; do i = 1 to varnum; call symput(name,named); call symput(label,labeled); end; run; data &libs..&mems; set &libs..&mems; rename &named = &labeled; run; %mend;

%relabel(NSW,PCS);

Any help would be appreciated as I have about 4000 variables to rename otherwise!!

Cheers

Dennis

--

Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail ist nicht gestattet.

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.


Back to: Top of message | Previous page | Main SAS-L page