<?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: How do I determine length of variable in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-determine-length-of-variable/m-p/599788#M18294</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/80196"&gt;@sri1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can see the benefit of reducing the length of a variable from $200 to $32, just as a matter of good housekeeping, if nothing else. And if you were to load your resulting data set&amp;nbsp; into memory (via the SASFILE statement or via a hash&amp;nbsp; object) you could save a meaningful amount of memory for a large collection.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But&amp;nbsp; I don't see nearly as much value in trying to cut down from $32, to (say) $15 based on the varnames actually in use.&amp;nbsp; Using $32 guarantees you always will have allocated enough space, and also means you don't have to inspect all the metadata in order to establish the absolute minimum necessary length.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 28 Oct 2019 13:28:37 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2019-10-28T13:28:37Z</dc:date>
    <item>
      <title>How do I determine length of variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-determine-length-of-variable/m-p/599756#M18282</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following sample code and want to create the variable "Name" with maximum length of strings in variable name instead of default $200 and I would like the length to be updated when the dataset changes.Is there anyway I can do in datastep?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data attrs;&lt;BR /&gt;dsid=open("sashelp.class", "i");&amp;nbsp;&lt;BR /&gt;n_vars=attrn(dsid, "nvars");&lt;BR /&gt;do i=1 to n_vars;&lt;BR /&gt;Name=varname(dsid, i);&lt;BR /&gt;Type=vartype(dsid, i);&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;rc=close(dsid);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your solutions are highly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 11:44:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-determine-length-of-variable/m-p/599756#M18282</guid>
      <dc:creator>sri1</dc:creator>
      <dc:date>2019-10-28T11:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do I determine length of variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-determine-length-of-variable/m-p/599759#M18283</link>
      <description>&lt;P&gt;Not that elegant. But it works.&lt;/P&gt;&lt;P&gt;Save the max length of name in a macro.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data attrs;
dsid=open("sashelp.class", "i"); 
n_vars=attrn(dsid, "nvars");
do i=1 to n_vars;
Name=varname(dsid, i);
Type=vartype(dsid, i);

output;
call symput('len',max(length(name)));

end;
rc=close(dsid);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Alter the length of the column.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
alter table attrs
  modify Name char(&amp;amp;len);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Oct 2019 12:18:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-determine-length-of-variable/m-p/599759#M18283</guid>
      <dc:creator>rudfaden</dc:creator>
      <dc:date>2019-10-28T12:18:17Z</dc:date>
    </item>
    <item>
      <title>Re: How do I determine length of variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-determine-length-of-variable/m-p/599760#M18284</link>
      <description>&lt;P&gt;I would assign a fixed length of $32 to the variable name, since that is the maximum allowable&amp;nbsp; length of any sas variable name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See &lt;A href="https://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p18cdcs4v5wd2dn1q0x296d3qek6.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;Rules for most SAS names&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 12:29:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-determine-length-of-variable/m-p/599760#M18284</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-10-28T12:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: How do I determine length of variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-determine-length-of-variable/m-p/599761#M18285</link>
      <description>&lt;P&gt;Why does it matter what length the variable has, as long as the length is not too SHORT?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select max(length(NAME)) into :max_length trimmed
  from sashelp.class
  ;
quit;

data class ;
  length name $&amp;amp;max_length. ;
  set sashelp.class;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Oct 2019 12:33:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-determine-length-of-variable/m-p/599761#M18285</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-28T12:33:19Z</dc:date>
    </item>
    <item>
      <title>Re: How do I determine length of variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-determine-length-of-variable/m-p/599763#M18287</link>
      <description>&lt;P&gt;If a variable is to long it will use unessesary space and SAS will run slower. Not a big deal if you have small dataset. But if you have billions of rows it matters.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 12:34:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-determine-length-of-variable/m-p/599763#M18287</guid>
      <dc:creator>rudfaden</dc:creator>
      <dc:date>2019-10-28T12:34:53Z</dc:date>
    </item>
    <item>
      <title>Re: How do I determine length of variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-determine-length-of-variable/m-p/599764#M18288</link>
      <description>&lt;P&gt;Question:&amp;nbsp;&amp;nbsp; Are you trying the determine the longest&amp;nbsp;length of all the varnames (that is my assumption)?&amp;nbsp;&amp;nbsp; Or are you trying to determine the longest value of a variable called NAME?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 12:42:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-determine-length-of-variable/m-p/599764#M18288</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-10-28T12:42:44Z</dc:date>
    </item>
    <item>
      <title>Re: How do I determine length of variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-determine-length-of-variable/m-p/599777#M18290</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp; You are right.I am&amp;nbsp;&lt;SPAN&gt;trying to&amp;nbsp; determine the longest&amp;nbsp;length of all the varnames&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 13:06:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-determine-length-of-variable/m-p/599777#M18290</guid>
      <dc:creator>sri1</dc:creator>
      <dc:date>2019-10-28T13:06:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do I determine length of variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-determine-length-of-variable/m-p/599779#M18291</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;Thanks for your reply.I am trying to determine the maximum length of all the varnames but not NAME column of sashelp.class&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 13:09:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-determine-length-of-variable/m-p/599779#M18291</guid>
      <dc:creator>sri1</dc:creator>
      <dc:date>2019-10-28T13:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: How do I determine length of variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-determine-length-of-variable/m-p/599781#M18292</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/80196"&gt;@sri1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;Thanks for your reply.I am trying to determine the maximum length of all the varnames but not NAME column of sashelp.class&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Huh?&amp;nbsp; Why?&amp;nbsp; What are you going the change once you know that information?&lt;/P&gt;
&lt;P&gt;The maximum length of a SAS variable name is 32 bytes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway the method to find the max is the same, only use as input the DICTIONARY metadata tables instead of the actual data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 13:14:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-determine-length-of-variable/m-p/599781#M18292</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-28T13:14:22Z</dc:date>
    </item>
    <item>
      <title>Re: How do I determine length of variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-determine-length-of-variable/m-p/599786#M18293</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; I know that&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;maximum length of a SAS variable name is 32 bytes but&amp;nbsp;to reduce the storage space.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 15:33:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-determine-length-of-variable/m-p/599786#M18293</guid>
      <dc:creator>sri1</dc:creator>
      <dc:date>2019-10-28T15:33:03Z</dc:date>
    </item>
    <item>
      <title>Re: How do I determine length of variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-determine-length-of-variable/m-p/599788#M18294</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/80196"&gt;@sri1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can see the benefit of reducing the length of a variable from $200 to $32, just as a matter of good housekeeping, if nothing else. And if you were to load your resulting data set&amp;nbsp; into memory (via the SASFILE statement or via a hash&amp;nbsp; object) you could save a meaningful amount of memory for a large collection.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But&amp;nbsp; I don't see nearly as much value in trying to cut down from $32, to (say) $15 based on the varnames actually in use.&amp;nbsp; Using $32 guarantees you always will have allocated enough space, and also means you don't have to inspect all the metadata in order to establish the absolute minimum necessary length.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 13:28:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-determine-length-of-variable/m-p/599788#M18294</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-10-28T13:28:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do I determine length of variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-determine-length-of-variable/m-p/599797#M18295</link>
      <description>&lt;P&gt;Consider using compression. I had a similar situation where I couldn't predict character variable length, and some outliers were VERY long, and when I used the compression option it reduced the overhead to a very manageable amount.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 14:03:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-determine-length-of-variable/m-p/599797#M18295</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2019-10-28T14:03:06Z</dc:date>
    </item>
  </channel>
</rss>

