Date: Tue, 19 Nov 2002 16:33:16 -0600
Reply-To: "Suzanne D. McCoy" <smccoy@LUCIDAN.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Suzanne D. McCoy" <smccoy@LUCIDAN.COM>
Subject: Re: proc report width=
In-Reply-To: <000801c2901b$1c9ea170$6a00a8c0@crs.local>
Content-Type: text/plain; charset=iso-8859-1
I'd have to play with the code a bit but you can definitely determine the
length of the longest word in the label using the length methodology.
Something like this:
%macro labellength;
proc sql noprint;
create table lengths(drop=len1-len10) as
select upcase(name) as name
, length(scan(label,1)) as len1
%do i=2 %to 10; /* just using a default here */
, length(scan(label,&i)) as len&i
%end;
, max(computed len1, ,....) as maxlength
from dictionary.columns
where libname='XXXXXXX'
and memname='YYYYYYYYY'
and type='char';
quit;
data _null_;
set lengths end=eof;
call symput(compress(name)||input(_n_,best.)),name);
call symput(compress(length)||input(_n_,best.)),input(maxlength,best.));
if eof then call symput("numcharvars",input(_n_,best.));
run;
%mend labellength;
--
Suzanne D. McCoy
Lucid Analytics Corp.
"Intelligence Unleashed"
> The flow option is not acceptable because I need the box option. It
> will not be too inefficient to find the max length for each variable.
> But what if the max length is shorter than the length of the longest
> word in the label. Then the labels will come out wrong. Is there
> anyway to access the length of the longest word in each label in the
> data step? I guess I could use proc contents. But that would require
> many more steps. It seems like there should be a simpler way of doing
> this.
>
>
>
>
> -----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
> Suzanne D. McCoy
> Sent: Tuesday, November 19, 2002 4:58 PM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Re: proc report width=
>
> You could also just shortcut the entire issue by using a default width
> for
> the columns and the flow option. The only macro alternative I can
> think of
> off the top is my head is to bump through the entire dataset again to
> determine the lengths via a max(length(for each variable)) and set them
> to
> macro variables, using dictionary.columns to determine the character
> variables, but what is that going to do to the efficiency/runtime?
>
> --
> Suzanne D. McCoy
> Lucid Analytics Corp.
> "Intelligence Unleashed"
>
>> I asked for this capability in PROC REPORT a while back; apparently
>> there's not enough perceived demand to warrant the programming effort.
>> If you want it, send mail to suggest@sas.com.
>>
>>
>>
>>
>> --
>> JackHamilton@FirstHealth.com
>> Manager, Technical Development
>> METRICS Department, First Health
>> West Sacramento, California USA
>>
>>
>>>>> Kevin Auslander <kauslander@TERRECRS.COM> 11/19/2002 1:33 PM >>>
>> I find that I frequently need to set the width of each
>> character variable manually when using proc report. I usually set it
>> to
>> a value that is equal to max(the longest word in the label, the length
>> of the longest data value). Setting the width for each variable
>> becomes
>> very tedious when I have to create several reports with many variables
>> each. I read in the help files that proc report will automatically
>set
>> the column width to accommodate the format of the variable. So what I
>> need is a macro that will set the format of each variable to max(the
>> longest word in the label, the length of the longest data value). Does
>> anyone out there have a macro that does this? Or does anyone have a
>> different solution to the problem. TIA
>>
>>
>> Kevin
|