<?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 Transform integer into decimal in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Transform-integer-into-decimal/m-p/918983#M41149</link>
    <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following table:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input Hosp1 Hosp2 ;&lt;BR /&gt;cards;&lt;BR /&gt;1234 112&lt;BR /&gt;345678 5623&lt;BR /&gt;212 32345&lt;BR /&gt;56762 1312&lt;BR /&gt;4002 7623451&lt;BR /&gt;78098 7712&lt;BR /&gt;1212 900087&lt;BR /&gt;5609 2432&lt;BR /&gt;;;;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to get the following table? In other words I need to add a point after the first 3 numbers from the beginning of the integer while leaving the integers with &amp;lt;= 3 numbers as they are. Thank you very much in advance!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="188px"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="93.625px" height="30px"&gt;Hosp1&lt;/TD&gt;
&lt;TD width="93.7083px" height="30px"&gt;Hosp2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="93.625px" height="30px"&gt;123.4&lt;/TD&gt;
&lt;TD width="93.7083px" height="30px"&gt;112&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="93.625px" height="30px"&gt;345.678&lt;/TD&gt;
&lt;TD width="93.7083px" height="30px"&gt;562.3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="93.625px" height="30px"&gt;212&lt;/TD&gt;
&lt;TD width="93.7083px" height="30px"&gt;323.45&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="93.625px" height="30px"&gt;567.62&lt;/TD&gt;
&lt;TD width="93.7083px" height="30px"&gt;131.2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="93.625px" height="30px"&gt;400.2&lt;/TD&gt;
&lt;TD width="93.7083px" height="30px"&gt;762.3451&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="93.625px" height="30px"&gt;780.98&lt;/TD&gt;
&lt;TD width="93.7083px" height="30px"&gt;771.2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="93.625px" height="30px"&gt;121.2&lt;/TD&gt;
&lt;TD width="93.7083px" height="30px"&gt;900.087&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="93.625px" height="30px"&gt;560.9&lt;/TD&gt;
&lt;TD width="93.7083px" height="30px"&gt;243.2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
    <pubDate>Tue, 05 Mar 2024 15:52:58 GMT</pubDate>
    <dc:creator>NewUsrStat</dc:creator>
    <dc:date>2024-03-05T15:52:58Z</dc:date>
    <item>
      <title>Transform integer into decimal</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Transform-integer-into-decimal/m-p/918983#M41149</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following table:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input Hosp1 Hosp2 ;&lt;BR /&gt;cards;&lt;BR /&gt;1234 112&lt;BR /&gt;345678 5623&lt;BR /&gt;212 32345&lt;BR /&gt;56762 1312&lt;BR /&gt;4002 7623451&lt;BR /&gt;78098 7712&lt;BR /&gt;1212 900087&lt;BR /&gt;5609 2432&lt;BR /&gt;;;;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to get the following table? In other words I need to add a point after the first 3 numbers from the beginning of the integer while leaving the integers with &amp;lt;= 3 numbers as they are. Thank you very much in advance!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="188px"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="93.625px" height="30px"&gt;Hosp1&lt;/TD&gt;
&lt;TD width="93.7083px" height="30px"&gt;Hosp2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="93.625px" height="30px"&gt;123.4&lt;/TD&gt;
&lt;TD width="93.7083px" height="30px"&gt;112&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="93.625px" height="30px"&gt;345.678&lt;/TD&gt;
&lt;TD width="93.7083px" height="30px"&gt;562.3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="93.625px" height="30px"&gt;212&lt;/TD&gt;
&lt;TD width="93.7083px" height="30px"&gt;323.45&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="93.625px" height="30px"&gt;567.62&lt;/TD&gt;
&lt;TD width="93.7083px" height="30px"&gt;131.2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="93.625px" height="30px"&gt;400.2&lt;/TD&gt;
&lt;TD width="93.7083px" height="30px"&gt;762.3451&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="93.625px" height="30px"&gt;780.98&lt;/TD&gt;
&lt;TD width="93.7083px" height="30px"&gt;771.2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="93.625px" height="30px"&gt;121.2&lt;/TD&gt;
&lt;TD width="93.7083px" height="30px"&gt;900.087&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="93.625px" height="30px"&gt;560.9&lt;/TD&gt;
&lt;TD width="93.7083px" height="30px"&gt;243.2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Tue, 05 Mar 2024 15:52:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Transform-integer-into-decimal/m-p/918983#M41149</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-03-05T15:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: Transform integer into decimal</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Transform-integer-into-decimal/m-p/918984#M41150</link>
      <description>&lt;P&gt;Sure.&lt;/P&gt;
&lt;P&gt;The first step is to clearly state the RULE (or rules) that define the changes you want to make.&lt;/P&gt;
&lt;P&gt;So you have this data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input Hosp1 Hosp2 ;
cards;
1234   112
345678 5623
212    32345
56762  1312
4002   7623451
78098  7712
1212   900087
5609   2432
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you expected this data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data expect;
 input Hosp1 Hosp2 ;
cards;
123.4   112
345.678 562.3
212     323.45
567.62  131.2
400.2   762.3451
780.98  771.2
121.2   900.087
560.9   243.2
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Looks to me like you wanted the decimal point after the third digit.&lt;/P&gt;
&lt;P&gt;For that&amp;nbsp;you can use the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/p1y030o3l1qq30n1ka9871o5rj1i.htm" target="_self"&gt;BZ informat&lt;/A&gt;.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  hosp1=input(put(hosp1,7.-L),bz7.4);
  hosp2=input(put(hosp2,7.-L),bz7.4);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;The COMPARE Procedure
Comparison of WORK.WANT with WORK.EXPECT
(Method=EXACT)

Data Set Summary

Dataset               Created          Modified  NVar    NObs

WORK.WANT    05MAR24:11:04:23  05MAR24:11:04:23     2       8
WORK.EXPECT  05MAR24:11:04:23  05MAR24:11:04:23     2       8


Variables Summary

Number of Variables in Common: 2.


Observation Summary

Observation      Base  Compare

First Obs           1        1
Last  Obs           8        8

Number of Observations in Common: 8.
Total Number of Observations Read from WORK.WANT: 8.
Total Number of Observations Read from WORK.EXPECT: 8.

Number of Observations with Some Compared Variables Unequal: 0.
Number of Observations with All Compared Variables Equal: 8.

NOTE: No unequal values were found. All values compared are exactly equal.
&lt;/PRE&gt;
&lt;P&gt;But the real question is why did you end up with the wrong value in the HAVE dataset?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How did you create the HAVE dataset?&amp;nbsp; Perhaps you can modify that step so that it is created with the right values directly.&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have2;
 input Hosp1 bz7.4 Hosp2 bz7.4 ;
cards;
1234   112
345678 5623
212    32345
56762  1312
4002   7623451
78098  7712
1212   900087
5609   2432
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2024 16:12:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Transform-integer-into-decimal/m-p/918984#M41150</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-05T16:12:12Z</dc:date>
    </item>
    <item>
      <title>Re: Transform integer into decimal</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Transform-integer-into-decimal/m-p/918985#M41151</link>
      <description>&lt;P&gt;Read as character then use a different Input for different lengths to imply a decimal value&lt;/P&gt;
&lt;PRE&gt;data have;
   input Hosp1 $ Hosp2 $ ;
   select (length(hosp1));
      when (1,2,3) Hosp1Num = input(hosp1,3.);
      when (4) Hosp1Num = input(hosp1,4.1);
      when (5) Hosp1Num = input(hosp1,5.2);
      when (6) Hosp1Num = input(hosp1,6.3);
      when (7) Hosp1Num = input(hosp1,7.4);
      otherwise put "WARNING: Unexpected length for Hosp1";
   end;
   select (length(hosp2));
      when (1,2,3) Hosp2Num = input(Hosp2,3.);
      when (4) Hosp2Num = input(Hosp2,4.1);
      when (5) Hosp2Num = input(Hosp2,5.2);
      when (6) Hosp2Num = input(Hosp2,6.3);
      when (7) Hosp2Num = input(Hosp2,7.4);
      otherwise put "WARNING: Unexpected length for Hosp2";
   end;
cards;
1234 112
345678 5623
212 32345
56762 1312
4002 7623451
78098 7712
1212 900087
5609 2432
;&lt;/PRE&gt;
&lt;P&gt;Probably just one way.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2024 16:14:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Transform-integer-into-decimal/m-p/918985#M41151</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-03-05T16:14:15Z</dc:date>
    </item>
    <item>
      <title>Re: Transform integer into decimal</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Transform-integer-into-decimal/m-p/918986#M41152</link>
      <description>&lt;P&gt;When there are 4 or more digits (i.e. value &amp;gt;=1000), you want to convert the value such that exactly three digits precede the decimal point.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming there is good reason to maintain these variables as numerics instead of character, then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have (drop=i);
  input hosp1 hosp2;
  array hosp {2} ;

  do i=1 to 2;
    do while (hosp{i}&amp;gt;=1000);
      hosp{i}=hosp{i}/10;
    end;
  end;
cards;
1234 112
345678 5623
212 32345
56762 1312
4002 7623451
78098 7712
1212 900087
5609 2432
;;;;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Mar 2024 16:23:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Transform-integer-into-decimal/m-p/918986#M41152</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-03-05T16:23:04Z</dc:date>
    </item>
    <item>
      <title>Re: Transform integer into decimal</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Transform-integer-into-decimal/m-p/918987#M41153</link>
      <description>&lt;P&gt;This is a very concise and elegant solution. Very nice,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2024 16:27:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Transform-integer-into-decimal/m-p/918987#M41153</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2024-03-05T16:27:05Z</dc:date>
    </item>
    <item>
      <title>Re: Transform integer into decimal</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Transform-integer-into-decimal/m-p/918991#M41154</link>
      <description>&lt;P&gt;One more approach. "Format-less".&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input Hosp1 Hosp2 ;
cards;
1234   112
345678 5623
212    32345
56762  1312
4002   7623451
78098  7712
1212   900087
5609   2432
;
run;

data want;
  set have;
    array H hosp1 hosp2;
    do over H;
      H = H/(10**max(0,ceil(log10(H))-3)); /* divide by 10,100,1000, etc. depending on digits number */
    end;
    format hosp1 hosp2 best.;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2024 16:47:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Transform-integer-into-decimal/m-p/918991#M41154</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-03-05T16:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: Transform integer into decimal</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Transform-integer-into-decimal/m-p/918993#M41155</link>
      <description>Thank you very much Tom! Unfortunately I received data in the "have" format.</description>
      <pubDate>Tue, 05 Mar 2024 16:49:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Transform-integer-into-decimal/m-p/918993#M41155</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-03-05T16:49:14Z</dc:date>
    </item>
    <item>
      <title>Re: Transform integer into decimal</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Transform-integer-into-decimal/m-p/918994#M41156</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134532"&gt;@NewUsrStat&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you very much Tom! Unfortunately I received data in the "have" format.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then you probably need to ask the supplier why they did that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that if any of the values could start with zero then you are in trouble figuring out where to up the decimal place.&amp;nbsp; For example consider the string:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1234&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is that supposed to be 123.4 or was it instead 012.34 or 001.234 ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are probably going to be better off storing these a CHARACTER variables instead of NUMERIC variables.&amp;nbsp; First off a CODE does not need to be a NUMBER because you cannot do arithmetic with it.&amp;nbsp; Second you can then have meaningful leading and/or trailing zeros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could either convert the original numbers you have.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;chosp1 = put(hosp1,7.-L);&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or if you define CHOSP1 as length $8 you could add the period in a second step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length chosp1 $8;
chosp1 = put(hosp1,7.-L);
chosp1 = substr(chosp1,1,3)||'.'||substr(chosp1,4);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Mar 2024 17:07:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Transform-integer-into-decimal/m-p/918994#M41156</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-05T17:07:14Z</dc:date>
    </item>
  </channel>
</rss>

