<?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: Help converting data using translate in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-converting-data-using-translate/m-p/675734#M203619</link>
    <description>&lt;P&gt;The problem is probably that the VARIABLE1 variable has a length of 8. So when you right-align it, you get one more leading zeros than you want, and the last character is cut off when assigning the value to VARIABLE2 which has a length of 7.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The easiest way out is probably just to drop the first leading zero:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;variable2 = substr(translate(right(variable1),"0"," "),2);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 10 Aug 2020 19:39:37 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2020-08-10T19:39:37Z</dc:date>
    <item>
      <title>Help converting data using translate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-converting-data-using-translate/m-p/675729#M203616</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;My first post. I am using SAS 9.4 in Windows. I am importing data from an Excel file. The data is alpha-numeric. The variables range in length from 2 to 7 characters. For example:&lt;/P&gt;&lt;P&gt;151&lt;/P&gt;&lt;P&gt;534&lt;/P&gt;&lt;P&gt;345697&lt;/P&gt;&lt;P&gt;1A875&lt;/P&gt;&lt;P&gt;The variables need to be 7 digits with leading zeroes. Assuming the variable I am importing is names 'variable1', the code i am using is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc import datafile="xxxxxxx.xlsx"&lt;BR /&gt;out=dataset1&lt;BR /&gt;dbms=xlsx ;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data dataset2;&lt;BR /&gt;set dataset1;&lt;BR /&gt;format variable2 $7.0 ;&lt;BR /&gt;variable2 = translate(right(variable1),"0"," ");&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The variables in the output set are 7 digits but it leaves off the last character. Using the above data set, the output is:&lt;/P&gt;&lt;P&gt;0000015&lt;/P&gt;&lt;P&gt;0000053&lt;/P&gt;&lt;P&gt;0034569&lt;/P&gt;&lt;P&gt;0001A87&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just can't get the right output and I know it worked last month!! Aiiiiii&lt;/P&gt;&lt;P&gt;Any advice?&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Aug 2020 19:23:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-converting-data-using-translate/m-p/675729#M203616</guid>
      <dc:creator>Mofro13</dc:creator>
      <dc:date>2020-08-10T19:23:49Z</dc:date>
    </item>
    <item>
      <title>Re: Help converting data using translate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-converting-data-using-translate/m-p/675734#M203619</link>
      <description>&lt;P&gt;The problem is probably that the VARIABLE1 variable has a length of 8. So when you right-align it, you get one more leading zeros than you want, and the last character is cut off when assigning the value to VARIABLE2 which has a length of 7.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The easiest way out is probably just to drop the first leading zero:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;variable2 = substr(translate(right(variable1),"0"," "),2);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Aug 2020 19:39:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-converting-data-using-translate/m-p/675734#M203619</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-08-10T19:39:37Z</dc:date>
    </item>
    <item>
      <title>Re: Help converting data using translate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-converting-data-using-translate/m-p/675739#M203620</link>
      <description>That did it. Thanks for the help!!</description>
      <pubDate>Mon, 10 Aug 2020 19:55:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-converting-data-using-translate/m-p/675739#M203620</guid>
      <dc:creator>Mofro13</dc:creator>
      <dc:date>2020-08-10T19:55:07Z</dc:date>
    </item>
  </channel>
</rss>

