<?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: Remove or Add Trailing Zeroes to a Variable Depending on Length in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Remove-or-Add-Trailing-Zeroes-to-a-Variable-Depending-on-Length/m-p/590011#M168823</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/227543"&gt;@TL93&lt;/a&gt;,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/227543"&gt;@TL93&lt;/a&gt;&amp;nbsp;wrote: Region is a&amp;nbsp;&lt;STRONG&gt;numeric&lt;/STRONG&gt;&amp;nbsp;variable and has a max character &lt;STRONG&gt;length of 10&lt;/STRONG&gt; (e.g. 5356789.02).&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If it's really a &lt;EM&gt;numeric&lt;/EM&gt; variable, a multiplication by 100 might work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dataset_1;
input region;
cards;
100010               
100020.01            
100020.02            
100033               
256006               
3451678.01 
;

data want;
set dataset_1;
region=round(region*100, 1e-6);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here's why the ROUND function (with an appropriate rounding unit, if any) should not be omitted:&lt;/P&gt;
&lt;PRE&gt;445  data _null_;
446  if 1.09*100 ne 109 then put 'Surprise!';
447  run;

Surprise!
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds&lt;/PRE&gt;</description>
    <pubDate>Thu, 19 Sep 2019 13:13:57 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2019-09-19T13:13:57Z</dc:date>
    <item>
      <title>Remove or Add Trailing Zeroes to a Variable Depending on Length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-or-Add-Trailing-Zeroes-to-a-Variable-Depending-on-Length/m-p/589890#M168780</link>
      <description>&lt;P&gt;Hi SAS Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to merge two datasets by&amp;nbsp;&lt;STRONG&gt;region.&amp;nbsp;&lt;/STRONG&gt;In general, some region values can end with decimal places and some don't. The problem is that&amp;nbsp;the&amp;nbsp;region variable values are slightly different between the datasets. In the first dataset, I get the original region values. In the second dataset, if the value does not end with decimal places then two zeroes ("00") are added. I believe the latter was done to make sure all values have the same lengths (to be honest, the reason why is beyond me). Moreover, in the second dataset, the decimal itself is removed from the value. I need region to be identically coded so I can merge the datasets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My goal is to either &lt;STRONG&gt;add&amp;nbsp;two zeroes&lt;/STRONG&gt;&amp;nbsp;to the end of the region values in dataset_1, where values do not end with decimals. Or, &lt;STRONG&gt;remove the&amp;nbsp;two trailing zeroes&lt;/STRONG&gt;&amp;nbsp;from the region values in dataset_2, where values end in two zeroes. I also want to either &lt;STRONG&gt;add or remove the decimal point&lt;/STRONG&gt;. Region is a&amp;nbsp;&lt;STRONG&gt;numeric&lt;/STRONG&gt;&amp;nbsp;variable and has a max character &lt;STRONG&gt;length of 10&lt;/STRONG&gt; (e.g. 5356789.02). Can anyone help me do this quickly? I have over 300+ region codes to deal with &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; I tabulate my data have and data want below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;DATA HAVE (region variable)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;dataset_1&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dataset_2&lt;/P&gt;&lt;P&gt;100010&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10001000&lt;/P&gt;&lt;P&gt;100020.01&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10002001&lt;/P&gt;&lt;P&gt;100020.02&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10002002&lt;/P&gt;&lt;P&gt;100033&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10003300&lt;/P&gt;&lt;P&gt;256006&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 25600600&lt;/P&gt;&lt;P&gt;3451678.01&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; &amp;nbsp; &amp;nbsp; &amp;nbsp;345167801&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;DATA WANT (region variable)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;dataset_1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;or&amp;nbsp; &amp;nbsp;&lt;/STRONG&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dataset_2&lt;/P&gt;&lt;P&gt;10001000&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 100010&lt;/P&gt;&lt;P&gt;10002001&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 100020.01&lt;/P&gt;&lt;P&gt;10002002&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 100020.02&lt;/P&gt;&lt;P&gt;10003300&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 100033&lt;/P&gt;&lt;P&gt;25600600&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 256006&lt;/P&gt;&lt;P&gt;345167801&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3451678.01&lt;/P&gt;&lt;P&gt;(I basically want the region values to be identical)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you, and please let me know if more information is required.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 02:22:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-or-Add-Trailing-Zeroes-to-a-Variable-Depending-on-Length/m-p/589890#M168780</guid>
      <dc:creator>TL93</dc:creator>
      <dc:date>2019-09-19T02:22:38Z</dc:date>
    </item>
    <item>
      <title>Re: Remove or Add Trailing Zeroes to a Variable Depending on Length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-or-Add-Trailing-Zeroes-to-a-Variable-Depending-on-Length/m-p/589891#M168781</link>
      <description>&lt;P&gt;Presumably the original DATASET_1 value never matches DATASET_2.&amp;nbsp; It always either has a decimal to be remove, or needs to have two zeroes concatenated to it.&amp;nbsp; If so then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  if indexc(dataset_1,'.')&amp;gt;0 then new_dataset_1=compress(dataset_1,'.');  
  else new_dataset_1=cats(dataset_1,'00');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The INDEXC function returns the position of the first instance of the second argumen ('.') found in the first argument (DATASET_1).&amp;nbsp; If there is no '.', a zero is returned.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The COMPRESS function returns the value of the first argument all instances of the second argument ('.') removed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and the CATS (concatenated with leading/trailing blanks stripped) just appends '00' to DATASET_1, with no intervening blanks.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 02:36:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-or-Add-Trailing-Zeroes-to-a-Variable-Depending-on-Length/m-p/589891#M168781</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-09-19T02:36:56Z</dc:date>
    </item>
    <item>
      <title>Re: Remove or Add Trailing Zeroes to a Variable Depending on Length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-or-Add-Trailing-Zeroes-to-a-Variable-Depending-on-Length/m-p/589905#M168788</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
  picture FMT other='0099999999' (mult=100);
run;
data TEST;
  input X $10.;
  Y=put(input(X,best.),fmt. -l);
cards;
100010               
100020.01            
100020.02            
100033               
256006               
3451678.01 
run;
proc print noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;&lt;BR /&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.TEST" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;X&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;Y&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;100010&lt;/TD&gt;
&lt;TD class="l data"&gt;10001000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;100020.01&lt;/TD&gt;
&lt;TD class="l data"&gt;10002001&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;100020.02&lt;/TD&gt;
&lt;TD class="l data"&gt;10002002&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;100033&lt;/TD&gt;
&lt;TD class="l data"&gt;10003300&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;256006&lt;/TD&gt;
&lt;TD class="l data"&gt;25600600&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;3451678.01&lt;/TD&gt;
&lt;TD class="l data"&gt;345167801&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 04:36:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-or-Add-Trailing-Zeroes-to-a-Variable-Depending-on-Length/m-p/589905#M168788</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-09-19T04:36:30Z</dc:date>
    </item>
    <item>
      <title>Re: Remove or Add Trailing Zeroes to a Variable Depending on Length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-or-Add-Trailing-Zeroes-to-a-Variable-Depending-on-Length/m-p/590011#M168823</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/227543"&gt;@TL93&lt;/a&gt;,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/227543"&gt;@TL93&lt;/a&gt;&amp;nbsp;wrote: Region is a&amp;nbsp;&lt;STRONG&gt;numeric&lt;/STRONG&gt;&amp;nbsp;variable and has a max character &lt;STRONG&gt;length of 10&lt;/STRONG&gt; (e.g. 5356789.02).&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If it's really a &lt;EM&gt;numeric&lt;/EM&gt; variable, a multiplication by 100 might work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dataset_1;
input region;
cards;
100010               
100020.01            
100020.02            
100033               
256006               
3451678.01 
;

data want;
set dataset_1;
region=round(region*100, 1e-6);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here's why the ROUND function (with an appropriate rounding unit, if any) should not be omitted:&lt;/P&gt;
&lt;PRE&gt;445  data _null_;
446  if 1.09*100 ne 109 then put 'Surprise!';
447  run;

Surprise!
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Sep 2019 13:13:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-or-Add-Trailing-Zeroes-to-a-Variable-Depending-on-Length/m-p/590011#M168823</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-09-19T13:13:57Z</dc:date>
    </item>
    <item>
      <title>Re: Remove or Add Trailing Zeroes to a Variable Depending on Length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-or-Add-Trailing-Zeroes-to-a-Variable-Depending-on-Length/m-p/590173#M168873</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/227543"&gt;@TL93&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Instead of matching one to the other, I'd rather convert both to the same pattern. You're saying that your region variable is "numeric", but it looks like mean that its printed content looks like a number - either integer or decimal - while it is &lt;EM&gt;stored&lt;/EM&gt; as a character data type of length 10 (confirmed by the fact that in your sample the values are left-justified). If so, you can do the same transformation on both sides:&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dataset_1 ;                      
  input region $10. ;                 
  cards ;                             
100010                                
100020.01                             
100020.02                             
100033                                
256006                                
3451678.01                            
;                                     
run ;                                 
data dataset_2 ;                      
  input region $10. ;                 
  cards ;                             
10001000                              
10002001                              
10002002                              
10003300                              
25600600                              
345167801                             
;                                     
run ;                                 
                                      
%let pattern = 0000000000 ;           
                                      
data dataset_1_key (drop = _:) ;      
  set dataset_1 ;                     
  key = "&amp;amp;pattern" ;                  
  _r = compress (region, ".") ;       
  substr (key, 1, length (_r))  = _r ;
run ;                                 
                                      
data dataset_2_key (drop = _:) ;      
  set dataset_2 ;                     
  key = "&amp;amp;pattern" ;                  
  _r = compress (region, ".") ;       
  substr (key, 1, length (_r))  = _r ;
run ;                                 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can match by KEY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 19:48:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-or-Add-Trailing-Zeroes-to-a-Variable-Depending-on-Length/m-p/590173#M168873</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-09-19T19:48:13Z</dc:date>
    </item>
  </channel>
</rss>

