Date: Mon, 21 Oct 1996 18:53:22 EDT
Reply-To: rhoadsm1@WESTATPO.WESTAT.COM
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Mike Rhoads <rhoadsm1@WESTATPO.WESTAT.COM>
Subject: Re: This Format and Length Change Shouldn't Be Difficult
In response to Les Becker's question about changing the length of a
character variable on a SAS data set (original question at end of this posting)
...
You are probably running into two issues: (1) PROC DATASETS only allows
you to modify those attributes of variables that can be accomplished without
touching the data itself, since it only changes the "header" portion of your
data set. Thus, you cannot change a variable's type or length, although you can
change its name or label, or format/informat as long as the length does not
change.
(2) Once the DATA step compiler encounters a character variable in such a
way that it can figure out its length (e.g., by SETting an existing data set),
its length is set for the duration of that step and cannot be changed. Thus,
the solution has to be to put your LENGTH statement BEFORE your SET statement:
data mydsn;
length charvar $ 8;
set mydsn;
/* follow this with assignment statements etc. */
...
Mike Rhoads
Westat
RhoadsM1@Westat.com
<<original question>>
I have spent way too much time trying to reformat a variable in a SAS
dataset. Perhaps a generous soul will lend a hand. I have a variable
with a length of 7 and a format of $7. in a sas data set on a vax
system. I merely wish to alter the length to 8 and format to $8. so
that I can insert a digit into this character variable (it's an ID
number). I have tried various combination of length and format
statements and even tried modify in proc datasets. I seem to get
various messages that the length has already been set, or the code I
write is ineffective and the last digit of the character variable is
truncated. I'm certain that there is an simple solution to this prpb;em
that I have overlooked. BTW, when I merely try to set my old variable
(length of 7) equal to the new variable (length of 8), the character
string is truncated.
TIA for your suggestions. Feel free to respond directly to me; I'll
repost a summary of the responses. Also, is this is answered in a FAQ,
I'd appreciate a reference to where and access instructions.
Les
<***************************************************************************>
Les R. Becker, MA, NREMT-P
Evaluation Manager
Division of Injury and Disability Prevention
Maryland Department of Health and Mental Hygiene
201 W. Preston Street
Baltimore MD 21201
lrb2@cris.com Voice: (410) 767-5780 FAX: (410) 333-7279
and
Paramedic II
Bureau of Advanced Emergency Medical Services
Prince George's County Fire Department, Maryland
******************************************************************************
* *
* FOR THE VIEWS EXPRESSED HERE THERE IS ONLY MYSELF TO BLAME *
* *
******************************************************************************