<?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 compress in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/compress/m-p/803733#M316475</link>
    <description>&lt;PRE&gt;dual = compress(substr(acc,1,8) || put (( input(substr(acc,9,1),1.),5.) ||
substr(acc,10,7) || put (( input(substr(acc,17,1),1.)+1),5.) || substr (acc,18,2)," ");&lt;/PRE&gt;
&lt;P&gt;I have trouble understand the above, could you enlighten me?&lt;/P&gt;
&lt;P&gt;especially the put, input part, is it bad practice to write this kind of code? why so complicated, there is no single function to do put, input together?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;very scary code the big paragraph above...&lt;/P&gt;</description>
    <pubDate>Thu, 24 Mar 2022 03:55:03 GMT</pubDate>
    <dc:creator>HeatherNewton</dc:creator>
    <dc:date>2022-03-24T03:55:03Z</dc:date>
    <item>
      <title>compress</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compress/m-p/803733#M316475</link>
      <description>&lt;PRE&gt;dual = compress(substr(acc,1,8) || put (( input(substr(acc,9,1),1.),5.) ||
substr(acc,10,7) || put (( input(substr(acc,17,1),1.)+1),5.) || substr (acc,18,2)," ");&lt;/PRE&gt;
&lt;P&gt;I have trouble understand the above, could you enlighten me?&lt;/P&gt;
&lt;P&gt;especially the put, input part, is it bad practice to write this kind of code? why so complicated, there is no single function to do put, input together?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;very scary code the big paragraph above...&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2022 03:55:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compress/m-p/803733#M316475</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-03-24T03:55:03Z</dc:date>
    </item>
    <item>
      <title>Re: compress</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compress/m-p/803735#M316477</link>
      <description>&lt;P&gt;What does ACC contain?&lt;BR /&gt;What do you want DUAL to contain?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You seem to have too many left parenthesis. In particular why are their two left parenthesis in the PUT() function calls?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even if we fixt that doesn't make much sense&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put( input(substr(acc,9,1),1.) , 5. )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So you take a single character from ACC, convert it to a number between 0 and 9 then write it back as a character string with four spaces and the original single digit again and then later you remove the four spaces that were inserted. So why not just use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;substr(acc,9,1)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can reduce this a lot by using the CATS() function instead of || operator. Then there is might be no need for the COMPRESS() function.&lt;/P&gt;
&lt;PRE&gt;23820  data test;
23821   acc='................7...';
23822   dual=cats(substr(acc,1,16),input(substr(acc,17,1),1.)+1,substr(acc,18,2));
23823   put acc / dual ;
23824  run;

................7...
................8..
&lt;/PRE&gt;
&lt;P&gt;Or perhaps even simplier&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dual=acc;
substr(dual,17,1) = put(input(substr(dual,17,1),1.)+1,1.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Mar 2022 04:49:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compress/m-p/803735#M316477</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-24T04:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: compress</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compress/m-p/803736#M316478</link>
      <description>&lt;P&gt;Without seeing actual values or understanding why it was written can't say if good or bad though there is very likely a lot of marginal at best code in this mess.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example this bit reads one character out of the variable, converts it to a number, which would be a sing digit and then puts it as 5 characters which be default means 4 leading spaces&lt;/P&gt;
&lt;PRE&gt;put (( input(substr(acc,9,1),1.),5.)&lt;/PRE&gt;
&lt;P&gt;This is marginally better as the input bit has something added to it so justifies the numeric conversion and could result in either a 1 or 2 digit number. Again it is put using 5 characters though&lt;/P&gt;
&lt;PRE&gt;put (( input(substr(acc,17,1),1.)+1),5.)&lt;/PRE&gt;
&lt;P&gt;and the compress removes the blanks. So the first bit I discuss above likely should have stopped with the&lt;/P&gt;
&lt;PRE&gt;substr(acc,9,1)&lt;/PRE&gt;
&lt;P&gt;But as I mentioned, without knowing 1) actual values, 2) what the result is supposed to be and 3) why the result should look that way, I can't say (That's a large economy sized hint). Was there any comment in the code or program description about what was being fixed and why?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not the ugliest thing I've written or anywhere near the longest, but when there long strings that need massaging to specific appearance such things happen.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sometimes such a combination of put and input is used because the original data was read poorly and fixes are needed. One such is when a "date" that looks like 20210517 was read as simple number but the desire is to have an actual SAS date value. The original source data should have been read with a yymmdd informat. Instead of writing a bunch of code to parse out bits it is simpler to Put the number into a text value that an Input function can use the proper input.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2022 04:52:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compress/m-p/803736#M316478</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-24T04:52:09Z</dc:date>
    </item>
  </channel>
</rss>

