<?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 Numeric formats in datasteps in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Numeric-formats-in-datasteps/m-p/236782#M43395</link>
    <description>&lt;P&gt;data have;&lt;/P&gt;
&lt;P&gt;a=99.99999999&lt;/P&gt;
&lt;P&gt;b=370.86899;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to convert a to read 99M and b to read 370K.&amp;nbsp; So in each case I want to read everything through the decimal point and then add the desired letters of either M or K.&amp;nbsp; I read about the picture function in sas though I have not used it much&lt;/P&gt;</description>
    <pubDate>Fri, 27 Nov 2015 22:22:13 GMT</pubDate>
    <dc:creator>Q1983</dc:creator>
    <dc:date>2015-11-27T22:22:13Z</dc:date>
    <item>
      <title>Numeric formats in datasteps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-formats-in-datasteps/m-p/236782#M43395</link>
      <description>&lt;P&gt;data have;&lt;/P&gt;
&lt;P&gt;a=99.99999999&lt;/P&gt;
&lt;P&gt;b=370.86899;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to convert a to read 99M and b to read 370K.&amp;nbsp; So in each case I want to read everything through the decimal point and then add the desired letters of either M or K.&amp;nbsp; I read about the picture function in sas though I have not used it much&lt;/P&gt;</description>
      <pubDate>Fri, 27 Nov 2015 22:22:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-formats-in-datasteps/m-p/236782#M43395</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2015-11-27T22:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric formats in datasteps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-formats-in-datasteps/m-p/236787#M43398</link>
      <description>&lt;P&gt;And how do you know whether to use a "K" or an "M"? &amp;nbsp;I'm going to guess at your answer and suggest some code that would become part of a DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;a_text = put(a, best16.);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;a_text = left(a_text);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;m_or_k = length(a_text) - index(a_text, '.') - 2;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;a_text = left(put(int(a), 5.)) || substr('KM', m_or_k/3, 1);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you would like to clarify what your method is for assigning "K" or "M", I might need to adjust the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Nov 2015 23:52:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-formats-in-datasteps/m-p/236787#M43398</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-11-27T23:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric formats in datasteps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-formats-in-datasteps/m-p/236799#M43402</link>
      <description>&lt;P&gt;Since you don't want to round the numbers but simply drop the decimals, I think you should define function formats such as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=sasuser.fcmp.format;
function intk(x) $8;
    return (cats(int(x),"K"));
endsub;
function intm(x) $8;
    return (cats(int(x),"M"));
endsub;
run;

options cmplib=sasuser.fcmp;

proc format;
value intk (default=8) other = [intk()];
value intm (default=8) other = [intm()];
run;

data have;
a=99.99999999;
b=370.86899;
format a intm. b intk.;
run;

proc print data=have; run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 28 Nov 2015 04:48:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-formats-in-datasteps/m-p/236799#M43402</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-11-28T04:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric formats in datasteps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-formats-in-datasteps/m-p/236802#M43403</link>
      <description>&lt;PRE&gt;A different Approach  


data have;
input ID$ Number$;
NewID = INDEX(Number,'.');
newid1 = substr(Number,1,NewID);
target='.';
replacement='M';
replacement1='K';
if NewID = 3 then do ;
Ineedthisvalue=transtrn(newid1,target,replacement);
end;
Else do;
Ineedthisvalue=transtrn(newid1,target,replacement1);
end;
drop target replacement replacement1 newid1;
datalines; 
A 99.99999999
B 370.86899
;
run;
Proc Print data = have;
run;


&lt;/PRE&gt;</description>
      <pubDate>Sat, 28 Nov 2015 09:06:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-formats-in-datasteps/m-p/236802#M43403</guid>
      <dc:creator>pearsoninst</dc:creator>
      <dc:date>2015-11-28T09:06:04Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric formats in datasteps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-formats-in-datasteps/m-p/236828#M43407</link>
      <description>&lt;P&gt;Untested, but wouldn't a simple picture format do the job?&lt;/P&gt;</description>
      <pubDate>Sun, 29 Nov 2015 12:16:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-formats-in-datasteps/m-p/236828#M43407</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2015-11-29T12:16:46Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric formats in datasteps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-formats-in-datasteps/m-p/236851#M43410</link>
      <description>&lt;P&gt;Picture formats don't work all the time, look at pick. and picm. below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=sasuser.fcmp.format;
function intk(x) $8;
    return (cats(int(x),"K"));
endsub;
function intm(x) $8;
    return (cats(int(x),"M"));
endsub;
run;

options cmplib=sasuser.fcmp;

proc format;
value intk (default=8) other = [intk()];
value intm (default=8) other = [intm()];
picture pick other = "009K";
picture picm other = "009M";
run;

data have;
a=99.99999999; aa=a;
b=370.86899; bb=b;
format a intm. b intk. aa picm. bb pick.;
run;

proc print data=have; run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;                         Obs     a      aa      b       bb

                          1     99M    100M    370K    370K
&lt;/PRE&gt;</description>
      <pubDate>Sun, 29 Nov 2015 19:30:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-formats-in-datasteps/m-p/236851#M43410</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-11-29T19:30:47Z</dc:date>
    </item>
  </channel>
</rss>

