|Date: ||Wed, 23 Jun 2004 22:08:49 -0400|
|Reply-To: ||Lou <lpogodajr292185@COMCAST.NET>|
|Sender: ||"SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>|
|From: ||Lou <lpogodajr292185@COMCAST.NET>|
|Subject: ||Re: how to increase width of formats for some characters
A couple of points.
If you're using _all_ in your array statement, all the variable you're
dealing with must be the same type, character or numeric. You don't tell us
which you're dealing with.
In 8.2, variables don't have a format unless one is assigned, though they do
have a width.
I confess that I'm having difficulty unraveling your code. I'd tend to
break the process up into steps. Assuming you're dealing with character
variables and what you want to do is assign a format that is three spaces
larger than the width, I'd do something along the lines of the following
create table vars as
select name, length, varnum
where libname = 'WORK' and
memname = 'TEST' and
type = 'char'
order by name;
/* assuming the list is in another dataset, do a merge to see which
variables to increase */
proc sort data = list;
merge vars (in = vars)
list (in = list);
newlength = length;
if list then newlength = length + 3;
/* write the new format names to macro variables */
call symput('newfmt_' || compress(put(varnum, best.)), '$' ||
compress(put(newlength, best.)) || '.');
"Brian K. Bouvier" <bbouvier@FFIC.COM> wrote in message
> I'm trying to create a series of macro variables (newfmt1 -- newfmt99 one
> for each variable in a data set) that has the following property:
> if the data set variable is on a list, the value of the macro variable is
> the format of the data set variable + 3
> if the data set variable is NOT on a list, the value of the macro variable
> is the format of the data set variable
> I need to keep the same order as the position of the data set variables.
> for example, newfmt1 must correspond to the first data set variable,
> newfmt2 the second, etc.
> I don't know the names of the data set varaibles or how many of them there
> Here is the approach I'm starting with:
> data _null_;
> set work.ale(obs=0);
> array allvars(*) _all_;
> do i=1 to dim(allvars);
> if put(VNAME(allvars(i)),$lzero.) = 'Y' then /* if the variable is on
> the list, increase format width */
> call symput("newfmt"||left(put(i,3.)),compress(VFORMATN(allvars(i)) ||
> (VFORMATW(allvars(i))+3,3.) || '.' || put(VFORMATD(allvars(i)),3.)));
> else call symput("newfmt"||left(put(i,3.)),compress(VFORMAT(allvars
> Any other ideas?