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 (February 2012, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 17 Feb 2012 09:24:31 -0500
Reply-To:   Tom Abernathy <tom.abernathy@GMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Tom Abernathy <tom.abernathy@GMAIL.COM>
Subject:   Re: Assign Labels to Variables When Referencing Them by Array Elements

For your problem it seems to me the easiest solution is to use your editor to repeat the label statement 12 times and manually change the variable names. If you are using the SAS program editor just type one label statement and then in the space with the numbers enter R11 to repeat it 11 more times.

You cannot do that at execution phase of a DATA step. It needs to happen at the compile step. To make it easier you need to generate code. You could do that with a macro, use a PROC SQL query to store the code in a macro variable or write the code to file to be included.

Here is the example using a DATA step to generate the code.

filename code temp; data _null_; file code; do var = 'jan','feb','mar'; put 'label ' var '="X2";' ; end; run;

data .... ; %include code ; .... run;

You could also generate the code to change the labels using PROC DATASETS. This has the advantage of being able to be run after the dataset has already been created.

On Fri, 17 Feb 2012 09:07:52 -0500, Jack Clark <jclark@HILLTOP.UMBC.EDU> wrote:

>Hello, > > >I have variables which are monthly coverage groups. I have them defined >in an array, and I am processing them in a DO loop. One thing I would >like to do is add a LABEL to each variable, and the label value is the >same for each variable. I am trying to think of a way to do this in the >DO loop, but I am not having success. Both attempts below did not work. > > > >data test; > > jan = "X2"; > > feb = "X2"; > > mar = "X1"; > >run; > > > > > >data test2; > > set test; > >array v (3) jan feb mar; > > > >do i = 1 to 3; > > *label v(i) = "Monthly Coverage Group"; > > attrib vname(v(i)) label = "Monthly Coverage Group"; > >end; > >run; > > > >119 > >120 > >121 data test2; > >122 set test; > >123 array v (3) jan feb mar; > >124 > >125 do i = 1 to 3; > >126 *label v(i) = "Monthly Coverage Group"; > >127 attrib vname(v(i)) label = "Monthly Coverage Group"; > > - > > 22 > > 76 > >ERROR 22-322: Syntax error, expecting one of the following: a name, -, >:, FORMAT, INFORMAT, > > LABEL, LABLE, LENGTH, TRANSCODE, _ALL_, _CHARACTER_, >_CHAR_, _NUMERIC_. > > > >ERROR 76-322: Syntax error, statement will be ignored. > > > >128 end; > >129 run; > > > >NOTE: The SAS System stopped processing this step because of errors. > >WARNING: The data set WORK.TEST2 may be incomplete. When this step was >stopped there were 0 > > observations and 4 variables. > >WARNING: Data set WORK.TEST2 was not replaced because this step was >stopped. > >NOTE: DATA statement used (Total process time): > > real time 0.00 seconds > > cpu time 0.00 > > > > > > > > > >I could also put all of the variables in a single ATTRIB statement >outside the DO loop, but would need a way to reference all the variables >in the array > > > >ATTRIB (some way to reference all variables in array) LABEL = "Monthly >Coverage Group"; > > > >Any ideas? Thanks. > > > >Jack > > > >Jack Clark >Senior Programmer >phone: 410-455-6256 >fax: 410-455-6850 >jclark@hilltop.umbc.edu > >University of Maryland, Baltimore County >Sondheim Hall, 3rd Floor >1000 Hilltop Circle >Baltimore, MD 21250 > >Please consider the environment before printing this e-mail and/or any attachments. > > >Confidentiality Notice: This e-mail may contain information that is legally privileged and that is intended only for the use of the addressee(s) named above. If you are not the intended recipient, you are hereby notified that any disclosure, copying of this e-mail, distribution, or action taken in reliance on the contents of this e-mail and/or documents attributed to this e-mail is strictly prohibited. If you have received this information in error, please notify the sender immediately by phone and delete this entire e-mail. Thank you.


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