<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Can I reduce length of character variables? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/596666#M171831</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
alter table tochange
  modify varname char(10) format=$10.;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 15 Oct 2019 21:31:02 GMT</pubDate>
    <dc:creator>ghosh</dc:creator>
    <dc:date>2019-10-15T21:31:02Z</dc:date>
    <item>
      <title>Can I reduce length of character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/596660#M171828</link>
      <description>&lt;P&gt;I have many character variables, whose lengths are far greater than necessary. For example, the maximum length of a variable is 10, but its length is defined as 20. Is there a way to minimize these lengths at once so that each variable's length is the same as the maximum length of the variable?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Oct 2019 21:01:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/596660#M171828</guid>
      <dc:creator>braam</dc:creator>
      <dc:date>2019-10-15T21:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: Can I reduce length of character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/596666#M171831</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
alter table tochange
  modify varname char(10) format=$10.;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Oct 2019 21:31:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/596666#M171831</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2019-10-15T21:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: Can I reduce length of character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/596675#M171838</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/78622"&gt;@ghosh&lt;/a&gt; Thanks. It's an intuitive solution. I have some follow-up questions.&lt;BR /&gt;&lt;BR /&gt;1. Is there a simple way to revise many character variables without listing them all? (I'm thinking of something like _char_,. char*, but didn't find anything). &lt;BR /&gt;&lt;BR /&gt;2. Or something like char1 (starting character variable in my list) -char10 (ending character variable)? I don't think there is something like this in SQL....&lt;BR /&gt;&lt;BR /&gt;3. The code that you share with me assigns 10 to length of a variable. Extending this, I'm wondering if it can be the same as the maximum length of the variable. Well, some of my character variables use less than 10 characters while others use more than 10. Thanks again for your help.</description>
      <pubDate>Tue, 15 Oct 2019 22:18:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/596675#M171838</guid>
      <dc:creator>braam</dc:creator>
      <dc:date>2019-10-15T22:18:59Z</dc:date>
    </item>
    <item>
      <title>Re: Can I reduce length of character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/596683#M171844</link>
      <description>&lt;P&gt;In places where lists of&amp;nbsp; variables are acceptable you can use _character_ to reference all the character variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It may for most purposes be easier just to change the display format when using the variables as Format will accept a list but most of the statements to actually modify the variable property, such as the example Proc SQL code will not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;format _character_ $5. ;&lt;/P&gt;
&lt;P&gt;for example would be for the duration of a procedure only use/display 5 characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could use Proc Datasets to permanently assign a format to all the variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And the ever popular question, if you only want a length of 10 &lt;STRONG&gt;why&lt;/STRONG&gt; is the length longer? You may consider going back to the step that created the variables and change the code. But we would have to see the code used to create the variables to provide ideas.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hint: Proc Import seldom gets the lengths you want and has potential other issues with character vs numeric values with some data sources.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Oct 2019 23:19:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/596683#M171844</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-10-15T23:19:05Z</dc:date>
    </item>
    <item>
      <title>Re: Can I reduce length of character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/596712#M171857</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/279507"&gt;@braam&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Yup, it's simple. For example (a copy of sashelp.class being used as a guinea pig):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                                                                                                                                                                                                                                     
  set sashelp.class ;                                                                                                                                                                                                                                           
run ;                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                
%let dsn = have ;                                                                                                                                                                                                                                               
                                                                                                                                                                                                                                                                
data _null_ ;                                                                                                                                                                                                                                                   
  array mm [99999] _temporary_ ;                                                                                                                                                                                                                                
  set &amp;amp;dsn end = end ;                                                                                                                                                                                                                                          
  array cc (j) _char_ ;                                                                                                                                                                                                                                         
  if dim (cc) = 0 then stop ;                                                                                                                                                                                                                                   
  do over cc ;                                                                                                                                                                                                                                                  
     mm[j] = mm[j] max length (cc) ;                                                                                                                                                                                                                            
  end ;                                                                                                                                                                                                                                                         
  if end ;                                                                                                                                                                                                                                                      
  call execute ("proc sql ;") ;                                                                                                                                                                                                                                 
  call execute ("  alter table &amp;amp;dsn modify ") ;                                                                                                                                                                                                                 
  length vname vdef vfmt $ 256 ;                                                                                                                                                                                                                                
  do over cc ;                                                                                                                                                                                                                                                  
    vname = cats ('"', vname (cc), '"n') ;                                                                                                                                                                                                                      
    vdef  = cats ("char (", mm[j], ")" ) ;                                                                                                                                                                                                                      
    vfmt  = cats ("format=$", mm[j], "." ) ;                                                                                                                                                                                                                    
    call execute (catx (" ", ifc (j &amp;gt; 1, ",", "  "), vname, vdef, vfmt)) ;                                                                                                                                                                                      
  end ;                                                                                                                                                                                                                                                         
  call execute ("; quit ;") ;                                                                                                                                                                                                                                   
run ;                             
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What you'll see in the log (if the system option MSGLEVEL=i is in effect) after the above runs:&lt;/P&gt;
&lt;PRE&gt;NOTE: CALL EXECUTE generated line.
1   + proc sql ;
2   +   alter table have modify
3   + "Name"n char (7) format=$7.
4   + , "Sex"n char (1) format=$1.
5   + ;
NOTE: Table WORK.HAVE has been modified, with 5 columns.
5   +   quit ;
&lt;/PRE&gt;
&lt;P&gt;If you happen to have no character variables in the file being processed in this manner, you'll get the harmless:&lt;/P&gt;
&lt;PRE&gt;WARNING: Defining an array with zero elements.
&lt;/PRE&gt;
&lt;P&gt;and no SQL will be generated. The warning can be avoided by recoding the step using CALL VNEXT instead of the array CC. The "big enough" array MM can be replaced by a hash table. You can use these possibilities as a SAS exercise if you'd like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 04:03:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/596712#M171857</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-16T04:03:37Z</dc:date>
    </item>
    <item>
      <title>Re: Can I reduce length of character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/596729#M171865</link>
      <description>&lt;P&gt;If the reason to reduce character variable lengths is to save disk space, then you can do this by re-writing your SAS datasets with the COMPRESS = YES or BINARY SAS option. Then you don't need to reduce lengths at all.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 03:16:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/596729#M171865</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-10-16T03:16:20Z</dc:date>
    </item>
    <item>
      <title>Re: Can I reduce length of character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/596740#M171867</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/78622"&gt;@ghosh&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
alter table tochange
  modify varname char(10) format=$10.;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;One major drawback of that method is that is no way to &lt;STRONG&gt;clear&lt;/STRONG&gt; the format attached to a variable with SQL syntax.&amp;nbsp; You can only set it something as in the example.&amp;nbsp; Or leave it unchanged.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if someone had (accidentally? mistakenly?) attached the $20. format to the variable VARNAME in the example above then you are forced to perpetuate the mistaken by attaching the $10. format as in the posted code, or else the format will stay $20. even after the length was shortened from 20 to 10.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you do want to remove the format attached to VARNAME you might want to use a data step to remake the dataset instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or use PROC DATASETS to remove the format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets nolist lib=work;
  modify tochange;
    format varname ;
  run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Oct 2019 04:43:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/596740#M171867</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-16T04:43:14Z</dc:date>
    </item>
    <item>
      <title>Re: Can I reduce length of character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/596765#M171870</link>
      <description>&lt;P&gt;There are many ways to approach this, mine is but one.&amp;nbsp; You'll get a warning about "Multiple lengths were specified...".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Get the %loop and %loop_control macros here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/loop_control.sa" target="_blank"&gt;https://github.com/scottbass/SAS/blob/master/Macro/loop.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/loop_control.sa" target="_blank"&gt;https://github.com/scottbass/SAS/blob/master/Macro/loop_control.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc copy in=sashelp out=work;
   select cars class shoes stocks zipcode;
run;

%macro code;
* get column metadata ;
proc contents data=&amp;amp;word out=contents (keep=name type length varnum) noprint;
run;

* get max length of character columns ;
data _null_;
   set &amp;amp;word end=eof;
   array chars{*} _character_;
   length _name_ $32 _max_length_ 8;
   if (_n_=1) then do;
      declare hash h();
      rc=h.defineKey("_name_");
      rc=h.defineData("_name_","_max_length_");
      rc=h.defineDone();
      do i=1 to dim(chars);
         _name_=vname(chars{i});
         rc=h.add();
      end;
   end;
   do i=1 to dim(chars);
      _name_=vname(chars{i});
      rc=h.find();
      _max_length_=max(_max_length_,length(chars{i}));
      rc=h.replace();
   end;
   if eof then do;
      rc=h.output(dataset:"work.max_length");
   end;
run;

* join ;
proc sql;
   create table attribs as
   select 
      a.name
      ,coalesce(b._max_length_,a.length) as length
      ,a.type
   from
      contents a
   left join
      max_length b
   on
      a.name=b._name_
   order by
      a.varnum
   ;
quit;

%macro attribs;
   %if (&amp;amp;type eq 1) %then %do;
      attrib &amp;amp;name length=&amp;amp;length;
   %end;
   %else %do;
      attrib &amp;amp;name length=$&amp;amp;length;
   %end;
%mend;

data &amp;amp;word._new;
   %loop_control(control=attribs,mname=attribs)
   set &amp;amp;word;
run;
%mend;

%loop(cars class shoes stocks zipcode)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 07:08:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/596765#M171870</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-10-16T07:08:17Z</dc:date>
    </item>
    <item>
      <title>Re: Can I reduce length of character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/596768#M171871</link>
      <description>&lt;P&gt;And here's a version using PROC SQL + ALTER TABLE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I always thought you had to re-run the data step if you wanted to change column length?&amp;nbsp; Is PROC SQL rewriting the table under the covers?&amp;nbsp; I didn't test with a big enough table to notice a performance difference.&amp;nbsp; But if it's just rewriting the dataset header and not having to rewrite the data, then this is definitely the better approach from a performance perspective.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Never too old to learn something new!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc copy in=sashelp out=work;
   select cars class shoes stocks zipcode;
run;

%macro code;
* get max length of character columns ;
data _null_;
   set &amp;amp;word end=eof;
   array chars{*} _character_;
   length _name_ $32 _max_length_ 8;
   if (_n_=1) then do;
      declare hash h();
      rc=h.defineKey("_name_");
      rc=h.defineData("_name_","_max_length_");
      rc=h.defineDone();
      do i=1 to dim(chars);
         _name_=vname(chars{i});
         rc=h.add();
      end;
   end;
   do i=1 to dim(chars);
      _name_=vname(chars{i});
      rc=h.find();
      _max_length_=max(_max_length_,length(chars{i}));
      rc=h.replace();
   end;
   if eof then do;
      rc=h.output(dataset:"work.max_length");
   end;
run;

%macro alter;
   %let _name_=%trim(&amp;amp;_name_);
   %if (&amp;amp;__iter__ gt 1) %then ,;
   "&amp;amp;_name_"n char(&amp;amp;_max_length_)
%mend;

proc sql;
   alter table &amp;amp;word 
   modify
   %loop_control(control=max_length,mname=alter)
   ;
quit;
%mend;

%loop(cars class shoes stocks zipcode)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Oct 2019 07:31:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/596768#M171871</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-10-16T07:31:49Z</dc:date>
    </item>
    <item>
      <title>Re: Can I reduce length of character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/596777#M171875</link>
      <description>&lt;P&gt;Since the (character) variables are aligned within an observation in close succession, changing the length of one requires a change of observation length, and that needs a complete rewrite. You'll most probably have more observations in a dataset page, among other things.&lt;/P&gt;
&lt;P&gt;It is a consequence of the way SAS stores datasets as sequential files, and not (e.g.) as separate blocks containing a single column each.&lt;/P&gt;
&lt;P&gt;The only operations that don't need a rewrite are pure header changes (formats, informants, labels, names) and things like appending or marking observations as deleted.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 08:44:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/596777#M171875</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-16T08:44:57Z</dc:date>
    </item>
    <item>
      <title>Re: Can I reduce length of character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/596780#M171878</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15043"&gt;@ScottBass&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Scott, too bad. As &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;has indicated, modifying the length of even a single variable does cause a complete rewrite. Just inflate a test data set like sashelp.class 1E6 times, and you'll see by the sheer ALTER execution time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 09:02:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/596780#M171878</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-16T09:02:54Z</dc:date>
    </item>
    <item>
      <title>Re: Can I reduce length of character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/597163#M172040</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, to be clear, that was my understanding:&amp;nbsp; to change the length of variable, the data set must be rewritten.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;While the ALTER TABLE ... MODIFY approach in SQL is "syntactically elegant", it must be recreating the table under the covers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I ran some test code in EG 7.15 which I've attached.&amp;nbsp; The execution time of the ALTER TABLE approach makes clear that the data set is recreated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is also evident is just how big an impact data set compression can make on performance, depending on the characteristics of the dataset (i.e. how much compression occurs).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(SAS Community Administrators:&amp;nbsp; can you work out a way to make it easier to attach a &lt;EM&gt;&lt;U&gt;&lt;STRONG&gt;SAS Enterprise Guide&lt;/STRONG&gt;&lt;/U&gt;&lt;/EM&gt; project!!!&amp;nbsp; At least improve the generic error message when the attachment is rejected.)&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 04:33:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/597163#M172040</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-10-17T04:33:00Z</dc:date>
    </item>
    <item>
      <title>Re: Can I reduce length of character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/597175#M172048</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15043"&gt;@ScottBass&lt;/a&gt;: First, thanks for sharing the project.&lt;/P&gt;
&lt;P&gt;It just occurred to me that instead of rewriting the data set with the new lengths, an SQL view with new lengths can be created (or a DATA step view but its syntax with renaming and dropping would be more tedious). However, if the data set is to be read repeatedly, just rewriting it with the new lengths looks like a more sensible choice. I've had to do it on a number of occasions, particularly when the data came from an external RDBMS table, whose VARCHAR columns were interpreted and stored by SAS as crazily long fixed-length variables (apparently, to cover the territory without losing data). I've invariably found the pain of making one full pass through the data to determine the minimal lengths well worth it compared to using compression, not to mention that certain IDE environments (e.g., SAS Studio) don't work quite well when your character variables containing at most 10 characters are stored with the system length of $1000 or worse. Whether using a reduced-lengths view is better than compression performance-wise is an open question to be tested.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 05:14:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/597175#M172048</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-17T05:14:03Z</dc:date>
    </item>
    <item>
      <title>Re: Can I reduce length of character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/598053#M172407</link>
      <description>&lt;P&gt;In the deep recesses of my mind, I thought I might be reinventing the wheel ("what was the name of that macro again???")&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;While it was fun coding my project, here is another approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A title="%squeeze macro" href="http://support.sas.com/kb/24/804.html" target="_blank" rel="noopener"&gt;http://support.sas.com/kb/24/804.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Google "%squeeze macro".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, see also these comments:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://groups.google.com/forum/#!msg/comp.soft-sys.sas/eTlvA9WimNM/HRq_G8W3N5QJ" target="_blank"&gt;https://groups.google.com/forum/#!msg/comp.soft-sys.sas/eTlvA9WimNM/HRq_G8W3N5QJ&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I haven't reviewed the code, just wanted to post here since it's on topic.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2019 08:03:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reduce-length-of-character-variables/m-p/598053#M172407</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-10-21T08:03:20Z</dc:date>
    </item>
  </channel>
</rss>

