<?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 to change several characters length in one data step? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-change-several-characters-length-in-one-data-step/m-p/191503#M36128</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You cannot use variable lists to change the length.&amp;nbsp; The variable lists only work on variables that are already defined, and once they are defined it is too late to change the length. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Update:&lt;/P&gt;&lt;P&gt;That is not 100% true. You can set the order with a retain without defining the length or type, but you still would need to list the names of the variables in the RETAIN statement.&lt;/P&gt;&lt;P&gt;So you could do:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data xx ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain name sex;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length _all_ $40;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set sashelp.class ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But it would be easier to just do:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data xx ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length name sex $40.;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp; set sashelp.class ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 01 Mar 2014 21:11:41 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2014-03-01T21:11:41Z</dc:date>
    <item>
      <title>how to change several characters length in one data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-change-several-characters-length-in-one-data-step/m-p/191501#M36126</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have import a file from access and there are several characters variables ,&lt;/P&gt;&lt;P&gt;by default, the length of variables are $255.&lt;/P&gt;&lt;P&gt;I have trying to use length statement to change them all together, but does not work&lt;img id="smileysad" class="emoticon emoticon-smileysad" src="https://communities.sas.com/i/smilies/16x16_smiley-sad.png" alt="Smiley Sad" title="Smiley Sad" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; length _char_ $40.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please help! Many thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 01 Mar 2014 19:18:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-change-several-characters-length-in-one-data-step/m-p/191501#M36126</guid>
      <dc:creator>LillianLee</dc:creator>
      <dc:date>2014-03-01T19:18:59Z</dc:date>
    </item>
    <item>
      <title>Re: how to change several characters length in one data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-change-several-characters-length-in-one-data-step/m-p/191502#M36127</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Aside from the fact that the length should be $40 and not $40., yes, it won't work that way.&amp;nbsp; One work-around might be:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;&amp;nbsp; select name&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; into :names separated by ' '&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from dictionary.columns&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where libname eq 'SASHELP' and&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; memname eq 'CLASS' and&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type eq 'char'&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length &amp;amp;names $40;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set sashelp.class;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 01 Mar 2014 20:13:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-change-several-characters-length-in-one-data-step/m-p/191502#M36127</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2014-03-01T20:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: how to change several characters length in one data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-change-several-characters-length-in-one-data-step/m-p/191503#M36128</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You cannot use variable lists to change the length.&amp;nbsp; The variable lists only work on variables that are already defined, and once they are defined it is too late to change the length. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Update:&lt;/P&gt;&lt;P&gt;That is not 100% true. You can set the order with a retain without defining the length or type, but you still would need to list the names of the variables in the RETAIN statement.&lt;/P&gt;&lt;P&gt;So you could do:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data xx ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain name sex;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length _all_ $40;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set sashelp.class ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But it would be easier to just do:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data xx ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length name sex $40.;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp; set sashelp.class ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 01 Mar 2014 21:11:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-change-several-characters-length-in-one-data-step/m-p/191503#M36128</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-03-01T21:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: how to change several characters length in one data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-change-several-characters-length-in-one-data-step/m-p/191504#M36129</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could try re-importing but using the DBMAX_TEXT option.&amp;nbsp; &lt;A class="active_link" href="https://support.sas.com/documentation/cdl/en/acreldb/65247/HTML/default/viewer.htm#n1aqglg4ftdj04n1eyvh2l3367ql.htm" title="https://support.sas.com/documentation/cdl/en/acreldb/65247/HTML/default/viewer.htm#n1aqglg4ftdj04n1eyvh2l3367ql.htm"&gt;SAS/ACCESS(R) 9.3 for Relational Databases: Reference, Second Edition&lt;/A&gt;&lt;/P&gt;&lt;P&gt;You could just leave the lengths as 255 and use the COMPRESS=yes option and SAS will not waste space storing the trailing spaces.&lt;/P&gt;&lt;P&gt;You could leave the length at 255 and attach a format.&lt;/P&gt;&lt;P&gt;data want ;&lt;/P&gt;&lt;P&gt; set have;&lt;/P&gt;&lt;P&gt; format _character_ $40.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or perhaps you just need to REMOVE the format that SAS/Access insists on attaching when you import data.&lt;/P&gt;&lt;P&gt;data want ;&lt;/P&gt;&lt;P&gt; set have;&lt;/P&gt;&lt;P&gt; format _character_ ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 01 Mar 2014 21:21:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-change-several-characters-length-in-one-data-step/m-p/191504#M36129</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-03-01T21:21:15Z</dc:date>
    </item>
    <item>
      <title>Re: how to change several characters length in one data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-change-several-characters-length-in-one-data-step/m-p/191505#M36130</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;yes, this will work for sure.&lt;/P&gt;&lt;P&gt;what I was trying is use _character_ to represent all character variables since I have more that 20 of them.&lt;/P&gt;&lt;P&gt;thanks anyway&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Mar 2014 14:13:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-change-several-characters-length-in-one-data-step/m-p/191505#M36130</guid>
      <dc:creator>LillianLee</dc:creator>
      <dc:date>2014-03-02T14:13:17Z</dc:date>
    </item>
    <item>
      <title>Re: how to change several characters length in one data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-change-several-characters-length-in-one-data-step/m-p/191506#M36131</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have tried both of them right after I proc import the file, but it dose not work:smileycry:&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Mar 2014 14:16:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-change-several-characters-length-in-one-data-step/m-p/191506#M36131</guid>
      <dc:creator>LillianLee</dc:creator>
      <dc:date>2014-03-02T14:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: how to change several characters length in one data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-change-several-characters-length-in-one-data-step/m-p/191507#M36132</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;this is wonderful!&amp;nbsp; I can keep this macro for my further work &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;thanks a lot!!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Mar 2014 14:22:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-change-several-characters-length-in-one-data-step/m-p/191507#M36132</guid>
      <dc:creator>LillianLee</dc:creator>
      <dc:date>2014-03-02T14:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to change several characters length in one data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-change-several-characters-length-in-one-data-step/m-p/191508#M36133</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Changing the format will not change the length, but what difference does it make if the variable is defined longer than it needs to be?&amp;nbsp; With the compress option on the extra spaces do not cause the stored dataset to be any bigger.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example try this little experiment and see that storing the same information in a variable of length $255 and one of length $40 end up taking the same amount of disk space.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;425&amp;nbsp;&amp;nbsp; data one(keep=long compress=yes) two(keep=short compress=yes);&lt;/P&gt;&lt;P&gt;426&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; length long $255 short $40 ;&lt;/P&gt;&lt;P&gt;427&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i=1 to 5000 ;&lt;/P&gt;&lt;P&gt;428&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; short='This is less than 40 characters.';&lt;/P&gt;&lt;P&gt;429&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; long=short;&lt;/P&gt;&lt;P&gt;430&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;431&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;432&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;NOTE: The data set WORK.ONE has 5000 observations and 1 variables.&lt;/P&gt;&lt;P&gt;NOTE: Compressing data set WORK.ONE decreased size by 75.00 percent.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Compressed is 5 pages; un-compressed would require 20 pages.&lt;/P&gt;&lt;P&gt;NOTE: The data set WORK.TWO has 5000 observations and 1 variables.&lt;/P&gt;&lt;P&gt;NOTE: Compressing data set WORK.TWO increased size by 25.00 percent.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Compressed is 5 pages; un-compressed would require 4 pages.&lt;/P&gt;&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.05 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cpu time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.04 seconds&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Mar 2014 15:53:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-change-several-characters-length-in-one-data-step/m-p/191508#M36133</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-03-02T15:53:24Z</dc:date>
    </item>
    <item>
      <title>Re: how to change several characters length in one data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-change-several-characters-length-in-one-data-step/m-p/191509#M36134</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A __default_attr="2431" __jive_macro_name="user" class="jive_macro jive_macro_user" data-objecttype="3" href="https://communities.sas.com/"&gt;&lt;/A&gt;: I disagree.&amp;nbsp; Whether compressed, or not, the shorter lengths lead to smaller file sizes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I ran the following two sets of code and then looked at the resulting file sizes:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;libname art "d:\art";&lt;/P&gt;&lt;P&gt;data art.long (keep=long) art.short (keep=short);&lt;/P&gt;&lt;P&gt;&amp;nbsp; length long $255 short $40 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i=1 to 5000 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; short='This is less than 40 characters.';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; long=short;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data art.long_compressed (keep=long compress=yes) art.short_compressed (keep=short compress=yes);&lt;/P&gt;&lt;P&gt;&amp;nbsp; length long $255 short $40 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i=1 to 5000 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; short='This is less than 40 characters.';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; long=short;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;which resulted in:&lt;/P&gt;&lt;P&gt;filename/size&lt;/P&gt;&lt;P&gt;long/1265kb&lt;/P&gt;&lt;P&gt;short/201kb&lt;/P&gt;&lt;P&gt;long_compressed/253kb&lt;/P&gt;&lt;P&gt;short_compressed/237kb&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As you can see, the short file is smaller in both cases.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Mar 2014 16:49:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-change-several-characters-length-in-one-data-step/m-p/191509#M36134</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2014-03-02T16:49:28Z</dc:date>
    </item>
    <item>
      <title>Re: how to change several characters length in one data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-change-several-characters-length-in-one-data-step/m-p/191510#M36135</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;But not by enough to get your knickers in a twist.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Mar 2014 16:51:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-change-several-characters-length-in-one-data-step/m-p/191510#M36135</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-03-02T16:51:29Z</dc:date>
    </item>
  </channel>
</rss>

