Date: Mon, 28 Feb 2000 09:31:22 -0500
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: Character variables and formats
Content-Type: text/plain; charset="windows-1252"
> From: BONNET Christophe [mailto:Christophe.BONNET@GEP.FR]
> I'd like to know if there is a way to define a variable as character,
> without defining its size. My problem is that I use a macro
> which defines a
> variable xxx. This variable can take different character
> values. First I
> don't want to limit the length if values are long. On the
> other hand I don't
> want to define a large length because I need to print the
> data and I don't
> want a 40 bytes long column when my column could be a 3 bytes one.
Since you are defining the variable in a macro you could do some processing
and either change the format associated with the variable or adjust the
length.
%LET WIDTH = 0;
data _NULL_;
retain MaxLength;
set WHATEVER(keep = CharVar) end = EndoFile;
MaxLength = max(MaxLength,length(CharVar)));
if EndoFile then call symput('MAXLEN',compress(put(MaxLength,3.)));
run;%put MaxLen<&MAXLEN.>;
then use either
proc DATASETS
modify WHATEVER;
format CharVar = $char&MAXLEN..;
%*NOTE SNAKE-EYES <..> mac-var delimiter suffix + format suffix;
or another data step with attribute or length statement;
data WHATEVER;
attrib CharVar length = $ &MAXLEN.
format = $char&MAXLEN..;
hth
Ron Fehd the macro maven CDC Atlanta GA USA RJF2@cdc.gov
---> cheerful provider of UNTESTED SAS code!*! <---