<?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 Reading tab-delimited data using a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-tab-delimited-data-using-a-macro/m-p/29266#M5500</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks.&amp;nbsp; I didn't know about the compress option.&amp;nbsp; However, it looks like that uses RLE to compress the value internally.&amp;nbsp; I was looking for something that would automatically reduce the "length" to the appropriate size.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 13 Oct 2011 21:18:28 GMT</pubDate>
    <dc:creator>WesBarris</dc:creator>
    <dc:date>2011-10-13T21:18:28Z</dc:date>
    <item>
      <title>Reading tab-delimited data using a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-tab-delimited-data-using-a-macro/m-p/29262#M5496</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have the following macro used for reading a tab-delimited file:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro readFile(fileRef=);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %let maxLen=:$100.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; infile &amp;amp;fileRef delimiter='09'x dsd;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; input wingband this &amp;amp;maxLen that &amp;amp;maxLen;&lt;/P&gt;&lt;P&gt;%mend readFile;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This works but the variables "this" and "that" maintain a length of 100 characters within sas.&lt;/P&gt;&lt;P&gt;Is there a way to specify a maximum length but have the variables be only as long as necessary&lt;/P&gt;&lt;P&gt;to hold their values?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Oct 2011 16:27:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-tab-delimited-data-using-a-macro/m-p/29262#M5496</guid>
      <dc:creator>WesBarris</dc:creator>
      <dc:date>2011-10-13T16:27:58Z</dc:date>
    </item>
    <item>
      <title>Reading tab-delimited data using a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-tab-delimited-data-using-a-macro/m-p/29263#M5497</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data foo;&lt;/P&gt;&lt;P&gt; infile cards truncover;&lt;/P&gt;&lt;P&gt; retain mlen_this 0 mlen_that 0;&lt;/P&gt;&lt;P&gt; input wingband this :$100. that $100.;&lt;/P&gt;&lt;P&gt; mlen_this=max(mlen_this,length(this));&lt;/P&gt;&lt;P&gt; mlen_that=max(mlen_that,length(that));&lt;/P&gt;&lt;P&gt; call symput('mlen_this','$' || put(mlen_this,best.));&lt;/P&gt;&lt;P&gt; call symput('mlen_that','$' || put(mlen_that,best.));&lt;/P&gt;&lt;P&gt; drop mlen:;&lt;/P&gt;&lt;P&gt; cards;&lt;/P&gt;&lt;P&gt;1 abcdef ab&lt;/P&gt;&lt;P&gt;2 abc abcd&lt;/P&gt;&lt;P&gt;3 ab abc&lt;/P&gt;&lt;P&gt;4 abcd abcde&lt;/P&gt;&lt;P&gt;5 a a&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data bar;&lt;/P&gt;&lt;P&gt; length this &amp;amp;mlen_this that &amp;amp;mlen_that;&lt;/P&gt;&lt;P&gt; set foo;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Oct 2011 17:30:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-tab-delimited-data-using-a-macro/m-p/29263#M5497</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2011-10-13T17:30:20Z</dc:date>
    </item>
    <item>
      <title>Reading tab-delimited data using a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-tab-delimited-data-using-a-macro/m-p/29264#M5498</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why?&lt;/P&gt;&lt;P&gt;Have you considered just using the compress=yes option so that SAS will not waste space storing the extra blanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can either use:&lt;/P&gt;&lt;P&gt;options compress=yes;&lt;/P&gt;&lt;P&gt;To apply it to all future datasets.&amp;nbsp; Or use it as a dataset option.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data new (compress=yes);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; infile ...;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; input ... ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Oct 2011 18:32:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-tab-delimited-data-using-a-macro/m-p/29264#M5498</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2011-10-13T18:32:22Z</dc:date>
    </item>
    <item>
      <title>Reading tab-delimited data using a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-tab-delimited-data-using-a-macro/m-p/29265#M5499</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since these are large character variables you are storing it would be best to use compress=char.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Oct 2011 19:43:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-tab-delimited-data-using-a-macro/m-p/29265#M5499</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2011-10-13T19:43:37Z</dc:date>
    </item>
    <item>
      <title>Reading tab-delimited data using a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-tab-delimited-data-using-a-macro/m-p/29266#M5500</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks.&amp;nbsp; I didn't know about the compress option.&amp;nbsp; However, it looks like that uses RLE to compress the value internally.&amp;nbsp; I was looking for something that would automatically reduce the "length" to the appropriate size.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Oct 2011 21:18:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-tab-delimited-data-using-a-macro/m-p/29266#M5500</guid>
      <dc:creator>WesBarris</dc:creator>
      <dc:date>2011-10-13T21:18:28Z</dc:date>
    </item>
    <item>
      <title>Reading tab-delimited data using a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-tab-delimited-data-using-a-macro/m-p/29267#M5501</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks FriedEgg.&amp;nbsp; Actually, the values are not necessarily that large.&amp;nbsp; I was just looking for a way to specify a sufficiently large default value for length but then automatically reduce the length according to the data.&amp;nbsp; I could determine the length of each variable manually, I was just trying to automate that (which you did show how to do in your example).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Oct 2011 21:20:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-tab-delimited-data-using-a-macro/m-p/29267#M5501</guid>
      <dc:creator>WesBarris</dc:creator>
      <dc:date>2011-10-13T21:20:46Z</dc:date>
    </item>
    <item>
      <title>Re: Reading tab-delimited data using a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-tab-delimited-data-using-a-macro/m-p/29268#M5502</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You will have to read the file more than once.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data length / view=length ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; infile &amp;amp;fileRef delimiter='09'x dsd end=eof truncover ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; length x1-x10 $200 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; input x1-x10;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; array var x1-x10;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; array len len1-len10;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do over x; len = lengthm(x); end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc summary data=length;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var len1-len10;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; output out=lengths max= ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Oct 2011 22:35:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-tab-delimited-data-using-a-macro/m-p/29268#M5502</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2011-10-13T22:35:45Z</dc:date>
    </item>
    <item>
      <title>Reading tab-delimited data using a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-tab-delimited-data-using-a-macro/m-p/29269#M5503</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Unless you use compression, SAS stores the length you define. Even with the $varying informat, a fixed length is defined for holding the variable that is the maximum width.&lt;/P&gt;&lt;P&gt;Compress=yes is equivalent to Compress=char . These are effective with less overheads on CPU and real time, than Compress=binary&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Oct 2011 10:39:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-tab-delimited-data-using-a-macro/m-p/29269#M5503</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-10-15T10:39:32Z</dc:date>
    </item>
    <item>
      <title>Re: Reading tab-delimited data using a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-tab-delimited-data-using-a-macro/m-p/29270#M5504</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I really like Fried Egg's approach, but would suggest a couple of small modifications for efficiency's sake:&lt;/P&gt;&lt;PRE&gt; data foo;
&amp;nbsp;&amp;nbsp; /* Add end=last to be able to detect the end of the input data&amp;nbsp;&amp;nbsp;&amp;nbsp; */
&amp;nbsp;&amp;nbsp; infile cards truncover end=last;
&amp;nbsp;&amp;nbsp; retain mlen_this 0 mlen_that 0;
&amp;nbsp;&amp;nbsp; /* To begin with, make the text variables as log as possible */
&amp;nbsp;&amp;nbsp; input wingband this :$32767. that :$32767.;
&amp;nbsp;&amp;nbsp; mlen_this=max(mlen_this,length(this));
&amp;nbsp;&amp;nbsp; mlen_that=max(mlen_that,length(that));
&amp;nbsp;&amp;nbsp; if last then do;
&amp;nbsp;&amp;nbsp; /* CALL SYMPUTXs need only be executed once, after the last record of the input data is read */
&amp;nbsp;&amp;nbsp; /* Use SYMPUTX instead of SYMPUT to trim leading &amp;amp; trailng spaces from values */
&amp;nbsp;&amp;nbsp; /* Just save the number, don't concatenate any text&amp;nbsp; */
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call symputx('mlen_this',mlen_this);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call symputx('mlen_that',mlen_that);
&amp;nbsp;&amp;nbsp; end;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
drop mlen:; 
cards; 
1 abcdef ab 
2 abc abcd 
3 ab abc 
4 abcd abcde 
5 a a 
; 
run;

&amp;nbsp;&amp;nbsp; /* Use the macro variable values to modify the table structure in place */
&amp;nbsp;&amp;nbsp; /* This should be more efficient that re-writing the data set with a DATA step */
proc sql; 
alter table work.foo
&amp;nbsp;&amp;nbsp; modify this char(&amp;amp;mlen_this),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; that char(&amp;amp;mlen_that) ;
quit; 
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 16 Oct 2011 18:49:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-tab-delimited-data-using-a-macro/m-p/29270#M5504</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2011-10-16T18:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: Reading tab-delimited data using a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-tab-delimited-data-using-a-macro/m-p/29271#M5505</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It is almost not. You need to guess the length of var firstly. But you do not know the length until after browsing&lt;/P&gt;&lt;P&gt;the whole file.&lt;/P&gt;&lt;P&gt;There is a workaround is to use proc import + guessingrow= ,then copy the code generated by SAS &lt;/P&gt;&lt;P&gt;into editor to tailor for yourself.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Oct 2011 05:33:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-tab-delimited-data-using-a-macro/m-p/29271#M5505</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-10-18T05:33:34Z</dc:date>
    </item>
    <item>
      <title>Reading tab-delimited data using a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-tab-delimited-data-using-a-macro/m-p/29272#M5506</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree with the modifications here, they are all beneficial to performance.&amp;nbsp; There is one issue with the exact implementation here that I see however.&amp;nbsp; The cards statement is unbuffered and cannot use the end option on the infile statement.&amp;nbsp; You could instead use the parmcards statement.&amp;nbsp; If this is not the case in a different OS or version of SAS I would be interested in knowing.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Oct 2011 17:30:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-tab-delimited-data-using-a-macro/m-p/29272#M5506</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2011-10-20T17:30:35Z</dc:date>
    </item>
    <item>
      <title>Re: Reading tab-delimited data using a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-tab-delimited-data-using-a-macro/m-p/29273#M5507</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yep, my bad - CARDS is unbuffered, and the END= option won't work here...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Oct 2011 00:31:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-tab-delimited-data-using-a-macro/m-p/29273#M5507</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2011-10-21T00:31:08Z</dc:date>
    </item>
  </channel>
</rss>

