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 14:20:55 +0000
Reply-To:   toby dunn <tobydunn@HOTMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   toby dunn <tobydunn@HOTMAIL.COM>
Subject:   Re: Assign Labels to Variables When Referencing Them by Array Elements
Comments:   To: jclark@hilltop.umbc.edu
In-Reply-To:   <456B52C41B724C41B96561D7AD283E7D01F0564A@mail.chpdm.umbc.edu>
Content-Type:   text/plain; charset="Windows-1252"

Jack, YOu can't do it in one step because assigning a label to a variable will be done at compile time and your do loop wont get happen until execution time. The easiest thing is to do something like create the labels in Proc SQL or have them written out to a temp file and then use the macro variable or %include the temp file back into either a data step or proc datasets.

Toby Dunn

If you get thrown from a horse, you have to get up and get back on, unless you landed on a cactus; then you have to roll around and scream in pain. “Any idiot can face a crisis—it’s day to day living that wears you out” ~ Anton Chekhov

> Date: Fri, 17 Feb 2012 09:07:52 -0500 > From: jclark@HILLTOP.UMBC.EDU > Subject: Assign Labels to Variables When Referencing Them by Array Elements > To: SAS-L@LISTSERV.UGA.EDU > > 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