LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (December 2005, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 9 Dec 2005 23:00:46 +0000
Reply-To:     toby dunn <tobydunn@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         toby dunn <tobydunn@HOTMAIL.COM>
Comments: To: iw1junk@COMCAST.NET
In-Reply-To:  <120920052216.10625.439A02570008F03D00002981220682469305029A06CE9907@comcast.net>
Content-Type: text/plain; format=flowed

Ian,

Hmmm I guess I miss read the question I was supposing that the poster was wanting to get labels from vars in data set A into vars in Data set B. Also that there were more than a handful of vars, I was thinking in the magnatude of say 100 + tha could possibly have long labels.

But your use of SQL is pretty cool.

The only advantage I see to spitting the label code out to a file rather than holding it into 200 byte chunks is that you dont have all those macro vars to worrie about. In general when I see code that starts creating a rather large amount of macro vars like mvar1 -- mvar500 I start to cring (perhaps I am prejudice against creating too many macro vars).

So to that end:

data w ; retain x y z 1 ; label x = "xxxxxxx" y = "yyyyyyy" z = "zzzzzzz" ; run ;

data Y ; retain x_d y_d z_d 1 ; ; run ;

/***************************/ /** Use Dictionary.columns **/ /***************************/

proc sql ; create table labels as select 'label '||strip(name)||'_d ="'||strip(label)||'" ;' as text from dictionary.columns where libname = 'WORK' and memname = 'W' and name in (select scan(name,1,'_d') as name from dictionary.columns where libname = 'WORK' and memname = 'Y' and substr(reverse(compress(name)),1,2) = 'd_' ) ; quit ;

/**************************/ /** Shoot code out to a temp**/ /** file. **/ /**************************/

filename lab temp ;

data _null_ ; file lab ; set labels ;

put text ; run ;

/***********************/ /** Attache labels in place **/ /***********************/

proc datasets ; modify y ; %include lab ; quit ;

proc contents data = Y ; run ;

Toby Dunn

From: Ian Whitlock <iw1junk@COMCAST.NET> Reply-To: iw1junk@COMCAST.NET To: SAS-L@LISTSERV.UGA.EDU Date: Fri, 9 Dec 2005 22:16:55 +0000

Toby,

I hope you don't run into any names like X__DAME.

This is probably a fix to a problem that went on and on last month so I suspect that a fix to the solution code would be best. There one had to force the variables into the order

Sub Sub__D Inform Inform__D........................

So let's assume he got that far and make use of that information. Here is executable model code.

data w ; retain x x_d y y_d z z_d 1 ; label x = "xxxxxxx" y = "yyyyyyy" z = "zzzzzzz" ; run ; proc contents data = w out = c noprint ; run ; proc sql ; select trim(q2.name) || " label=" || quote(trim(q1.label)) into: lablist separated by ", " from c as q1 , c as q2 where q2.varnum = q1.varnum + 1 and mod(q1.varnum,2) = 1 and 1 <= varnum <= 200 /* then 201 to 400, 401 to 600 etc */ ; alter table w modify &lablist ; quit ;

As you can see I do like lists, but have shown you how to process the code in chunks of 200 variables when labels run 255 bytes and names 32 bytes. (As I remember the conditions there were 55 variables, so chunking shouldn't be necessary.)

Incidentally, remember that SASHELP.VCOLUMN all the meta-data available before using the subsetting WHERE thus I would suggest using DICTIONARY.COLUMNS or PROC CONTENTS for speed. Speaking of efficiency, why pass the data to change labels?

Ian Whitlock ====================== Date: Fri, 9 Dec 2005 21:05:33 +0000 Reply-To: toby dunn <tobydunn@HOTMAIL.COM> Sender: "SAS(r) Discussion" From: toby dunn <tobydunn@HOTMAIL.COM> Subject: Re: Copy the Old Labels to New Variables Created Comments: To: subramanyam.phani@GMAIL.COM In-Reply-To: <1134160133.631895.175140@g14g2000cwa.googlegroups.com> Content-Type: text/plain; format=flowed SAs_my_life, You have three solutions that don't require excessive manual finger labor. 1.) Use a sql and load the labels into either a bunch of macro vars or a single macro var. I don't like this approach as the first way will make for a possible house keeping nightmare and teh second way here might fail as there is a character limit to the amount of info one can shove into a single macro var. 2.) You can create a sifisticated macro that will read the meta data form both files and copy the labels over. Do to time I will leave this to Ian as he can do this faster than I. and finally 3.) A non macro solution.

allocate a temp filename. Read the meta data from the dataset you want to get the labels from in a data null, use put statements to write your sas code that will relabel your vars. Then in a data step or proc datasets statement %include your code.

filename labels temp ; /**Get Var to copy label too**/ data one ; set sashelp.vcolumns ; where libname = 'XXX' and memname = 'YYY' and index(name,'__d') ; name = compress(name , '__d') ; run ; proc sql ; create table old as select name , label from dictionary.columns where libname = 'ZZZ' and memname = 'NNN' and name in (select name from one ) ; quit ; data _null_ ; file junk ; set old ; put 'label ' ||name||'__d = '|| label||';' ; run ; data Relabel ; set YYY ; %include (labels) ; run ;

Toby Dunn

From: SAS_my_life <subramanyam.phani@GMAIL.COM> Reply-To: SAS_my_life <subramanyam.phani@GMAIL.COM> To: SAS-L Subject: Copy the Old Labels to New Variables Created Date: Fri, 9 Dec 2005 12:28:53 -0800 Hello Guys, I have a Data set with List of variables like this Sub Sub__D Inform Inform__D........................ what I need to do is copy the labels of Sub to Sub__d with Decode infront of Label I tried something like this proc sql noprint; alter table ae_temp1 modify SUJ__D label = 'DECODE OF patient number'; quit; but this good only for one variable I need to look whole dataset look for the variables ending with __d and copy their labels. Thank you so much for the help and time I deeply appriciate all your help. thanks phani


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