<?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: Create variable using catx and convert to numeric in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Create-variable-using-catx-and-convert-to-numeric/m-p/423941#M68148</link>
    <description>&lt;P&gt;A minor quibble: 9,007,199,254,740,992 (call it X) is the&amp;nbsp;maximum &lt;EM&gt;&lt;STRONG&gt;consecutive&lt;/STRONG&gt;&lt;/EM&gt; integer SAS can precisely store on windows and unix:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the "rarely needed but worth knowing" category, SAS can also exactly store these integers, all&amp;nbsp;larger than X:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;All&amp;nbsp;even&amp;nbsp;integers X+2 through 2X&amp;nbsp; (other integers are rounded up or down)&lt;/LI&gt;
&lt;LI&gt;then all the 0mod4 (integers exactly divisible by 4) up through 4X&lt;/LI&gt;
&lt;LI&gt;then all the 0mod8 integers up through 8X&lt;/LI&gt;
&lt;LI&gt;etc.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Demonstration:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Sasfont"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Sasfont"&gt;_null_&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Sasfont"&gt;&amp;nbsp;&amp;nbsp;x=constant (&lt;/FONT&gt;&lt;FONT color="#800080" face="Sasfont"&gt;'exactint'&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;&amp;nbsp; put&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; x=&lt;/FONT&gt;&lt;FONT color="#008080" face="Sasfont"&gt;comma21.0&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;&amp;nbsp; do&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; delta=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Sasfont"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Sasfont"&gt;to&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Sasfont"&gt;8&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Sasfont"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Sasfont"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x2=x+delta;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; put&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; delta= x2=&lt;/FONT&gt;&lt;FONT color="#008080" face="Sasfont"&gt;comma21.0&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;&amp;nbsp; end&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Sasfont"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Dec 2017 18:17:20 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2017-12-28T18:17:20Z</dc:date>
    <item>
      <title>Create variable using catx and convert to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-variable-using-catx-and-convert-to-numeric/m-p/423767#M68139</link>
      <description>&lt;P&gt;I'd like to create a unique id combining two variables, year and id.&lt;/P&gt;&lt;P&gt;all I want is 20104961387856, 2015496138, 201149613878 in numeric format as a new variable. The demo below doesn't demonstrate the problem. It creates character variable "uid". However,&amp;nbsp;using my actual large dataset (N=1,5M) uid is created as numeric variable and also&amp;nbsp;found&amp;nbsp;in&amp;nbsp;sci-notation when&amp;nbsp;original variable gets more than&amp;nbsp;8 digits as shown in the image. Consequent proc freq doesn't work with uid in sci-notification. I'm surprised. I thought sci-not is just for display view. Any suggestions please? Again,&amp;nbsp;I need new variable "uid" as 20104961387856, 2015496138, 201149613878 in numeric format.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
input year id;
datalines;
2010 4961387856
2015 496138
2011 49613878
;

DATA have1; SET have;
uid=cats(year,id);
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;UID created from actual data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sas.png" style="width: 118px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/17543i362EE1D6A00B64CE/image-size/large?v=v2&amp;amp;px=999" role="button" title="sas.png" alt="sas.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Dec 2017 19:00:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-variable-using-catx-and-convert-to-numeric/m-p/423767#M68139</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2017-12-27T19:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: Create variable using catx and convert to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-variable-using-catx-and-convert-to-numeric/m-p/423768#M68140</link>
      <description>&lt;P&gt;If I understand you properly, the problem where the UID shows E12 is just formatting; what happens if you assign format 20.0 to the UID?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Dec 2017 19:10:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-variable-using-catx-and-convert-to-numeric/m-p/423768#M68140</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-12-27T19:10:26Z</dc:date>
    </item>
    <item>
      <title>Re: Create variable using catx and convert to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-variable-using-catx-and-convert-to-numeric/m-p/423773#M68141</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just tried: &lt;FONT face="Courier New"&gt;uid=input(cats(year,id_bf),&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New"&gt;20.0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;and it had no effect on "uid". I still can see e12 and e13. &lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Dec 2017 19:18:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-variable-using-catx-and-convert-to-numeric/m-p/423773#M68141</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2017-12-27T19:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: Create variable using catx and convert to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-variable-using-catx-and-convert-to-numeric/m-p/423774#M68142</link>
      <description>&lt;P&gt;That's not really what I meant.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That affects the assignment of values to UID and not how the result is displayed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How about&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DATA have1; SET have;
uid=cats(year,id)+0;
format uid 20.0;
run; &lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Dec 2017 19:23:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-variable-using-catx-and-convert-to-numeric/m-p/423774#M68142</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-12-27T19:23:32Z</dc:date>
    </item>
    <item>
      <title>Re: Create variable using catx and convert to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-variable-using-catx-and-convert-to-numeric/m-p/423775#M68143</link>
      <description>thanks for a solution. do you know why sci-notation affected my further programming? isn't it supposed to be for a display purpose only?</description>
      <pubDate>Wed, 27 Dec 2017 19:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-variable-using-catx-and-convert-to-numeric/m-p/423775#M68143</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2017-12-27T19:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: Create variable using catx and convert to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-variable-using-catx-and-convert-to-numeric/m-p/423791#M68144</link>
      <description>&lt;P&gt;Yes, formats are for display purposes.&amp;nbsp; When you run PROC freq, it uses a format to display the result.&amp;nbsp; So yes, formats effect the output of PROC freq.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Compare the output from these two FREQ steps:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  do id=20104961387856, 2015496138, 201149613878;
    output;
  end;
run;

proc freq data=have;
 tables id;
run;

proc freq data=have;
 tables id;
 format id 20.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you have a long numeric value like this, you will want to make sure you won't exceed the limit of SAS's numeric precision on your OS.&amp;nbsp; On Windows and unix, the maximum integer SAS can store precisely is 9,007,199,254,740,992.&amp;nbsp; See &lt;A href="http://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p0ji1unv6thm0dn1gp4t01a1u0g6.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#p1ikmedbli0rz2n1de001ryz895o.&amp;nbsp;" target="_blank"&gt;http://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p0ji1unv6thm0dn1gp4t01a1u0g6.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#p1ikmedbli0rz2n1de001ryz895o.&amp;nbsp;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Often it makes to store such values in character variables, to avoid precision issues.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Dec 2017 20:28:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-variable-using-catx-and-convert-to-numeric/m-p/423791#M68144</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2017-12-27T20:28:46Z</dc:date>
    </item>
    <item>
      <title>Re: Create variable using catx and convert to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-variable-using-catx-and-convert-to-numeric/m-p/423792#M68145</link>
      <description>&lt;P&gt;Why do you need these UID variables to be numeric, anyway? It seems like you are just adding work for yourself. It's not like you are going to try to find that average of UID, that doesn't make sense.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Dec 2017 20:38:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-variable-using-catx-and-convert-to-numeric/m-p/423792#M68145</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-12-27T20:38:05Z</dc:date>
    </item>
    <item>
      <title>Re: Create variable using catx and convert to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-variable-using-catx-and-convert-to-numeric/m-p/423941#M68148</link>
      <description>&lt;P&gt;A minor quibble: 9,007,199,254,740,992 (call it X) is the&amp;nbsp;maximum &lt;EM&gt;&lt;STRONG&gt;consecutive&lt;/STRONG&gt;&lt;/EM&gt; integer SAS can precisely store on windows and unix:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the "rarely needed but worth knowing" category, SAS can also exactly store these integers, all&amp;nbsp;larger than X:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;All&amp;nbsp;even&amp;nbsp;integers X+2 through 2X&amp;nbsp; (other integers are rounded up or down)&lt;/LI&gt;
&lt;LI&gt;then all the 0mod4 (integers exactly divisible by 4) up through 4X&lt;/LI&gt;
&lt;LI&gt;then all the 0mod8 integers up through 8X&lt;/LI&gt;
&lt;LI&gt;etc.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Demonstration:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Sasfont"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Sasfont"&gt;_null_&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Sasfont"&gt;&amp;nbsp;&amp;nbsp;x=constant (&lt;/FONT&gt;&lt;FONT color="#800080" face="Sasfont"&gt;'exactint'&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;&amp;nbsp; put&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; x=&lt;/FONT&gt;&lt;FONT color="#008080" face="Sasfont"&gt;comma21.0&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;&amp;nbsp; do&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; delta=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Sasfont"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Sasfont"&gt;to&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Sasfont"&gt;8&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Sasfont"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Sasfont"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x2=x+delta;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; put&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; delta= x2=&lt;/FONT&gt;&lt;FONT color="#008080" face="Sasfont"&gt;comma21.0&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;&amp;nbsp; end&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Sasfont"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2017 18:17:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-variable-using-catx-and-convert-to-numeric/m-p/423941#M68148</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-12-28T18:17:20Z</dc:date>
    </item>
  </channel>
</rss>

