Date: Tue, 28 Sep 2004 16:21:34 -0400
Reply-To: "Fehd, Ronald J." <RJF2@CDC.GOV>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Fehd, Ronald J." <RJF2@CDC.GOV>
Subject: Re: Providing initial value of variable
Content-Type: text/plain; charset="us-ascii"
> From: Alina Chu
>
> Okay, I know this is basic but I usually perform only
> standard data reporting using SAS. This time I need to
> initialize a field that is longer than I would want to
> manually type in as a constant.
>
> For example: variable is $CHAR80. I want to set the variable
> to initially be all zeroes (yes, I want to treat it as
> character later). I certainly could create a small external
> file with a sample field set that way and just read it in and
> set this variable to the read-in variable contents. But, I
> hope there is a way to do it internally.
oh, yes, that wheel has been invented and is in the function collection:
InitValue = repeat('0',79);
Off By One rule:
take the value '0' you already have one character
and add another 79 instances of this one character you already have one
of
to get the requested total of 80.
akin to having an array index start at 0
rather than 1
if you want to replace the blanks
then retain that value
retain zeroes80 '.';
zeroes80 = repeat('0',79);
SomeVar = 'abcd';
Len = length(SomeVar);
substr(SomeVar,len) = substr(Zeroes80,1,length(Zeroes80)-len);
hmmmmmmm
maybe this would be clearer:
SomeVar = trim(SomeVar) !! Zeroes80;
the declared length of SomeVar truncates the trailing zeroes.
Ron Fehd the macro maven CDC Atlanta GA USA
... where is that .sig that says: UnTested Code from the ClueGee! Wrx