<?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: return first digit of a numeric variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/return-first-digit-of-a-numeric-variable/m-p/52144#M10992</link>
    <description>Yes.You  need to convert it back to a numeric after it.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
    <pubDate>Tue, 19 Apr 2011 00:53:47 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2011-04-19T00:53:47Z</dc:date>
    <item>
      <title>return first digit of a numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/return-first-digit-of-a-numeric-variable/m-p/52136#M10984</link>
      <description>Ok, I've googled this and searched the sas website and i'm just not finding the answer to this most simple of questions:&lt;BR /&gt;
&lt;BR /&gt;
I need to return the first digit of a numeric variable into a new variable.  Can someone please give me the data step i need or the command in proc sql?&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
      <pubDate>Mon, 18 Apr 2011 03:27:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/return-first-digit-of-a-numeric-variable/m-p/52136#M10984</guid>
      <dc:creator>CharlesR</dc:creator>
      <dc:date>2011-04-18T03:27:45Z</dc:date>
    </item>
    <item>
      <title>Re: return first digit of a numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/return-first-digit-of-a-numeric-variable/m-p/52137#M10985</link>
      <description>[pre]&lt;BR /&gt;
data digit;&lt;BR /&gt;
 input id;&lt;BR /&gt;
datalines;&lt;BR /&gt;
107&lt;BR /&gt;
204&lt;BR /&gt;
508&lt;BR /&gt;
359&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
 create table want as&lt;BR /&gt;
  select *,left(put(id,best20.)) length=1 as firstdigit&lt;BR /&gt;
   from digit;&lt;BR /&gt;
quit;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Mon, 18 Apr 2011 10:18:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/return-first-digit-of-a-numeric-variable/m-p/52137#M10985</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-04-18T10:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: return first digit of a numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/return-first-digit-of-a-numeric-variable/m-p/52138#M10986</link>
      <description>Hi CharlesR,&lt;BR /&gt;
You can also make use of substr() funtion.&lt;BR /&gt;
&lt;BR /&gt;
data have;&lt;BR /&gt;
	input id;&lt;BR /&gt;
datalines;&lt;BR /&gt;
107&lt;BR /&gt;
204&lt;BR /&gt;
508&lt;BR /&gt;
359&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
data want;&lt;BR /&gt;
	set have;&lt;BR /&gt;
	length id2 $1;&lt;BR /&gt;
	id2 = substr(put(id,best12.),1,1);&lt;BR /&gt;
	put id2=;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Amar Mundankar.</description>
      <pubDate>Mon, 18 Apr 2011 11:43:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/return-first-digit-of-a-numeric-variable/m-p/52138#M10986</guid>
      <dc:creator>AmarMundankar</dc:creator>
      <dc:date>2011-04-18T11:43:38Z</dc:date>
    </item>
    <item>
      <title>Re: return first digit of a numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/return-first-digit-of-a-numeric-variable/m-p/52139#M10987</link>
      <description>you would need to use the left function as well:&lt;BR /&gt;
&lt;BR /&gt;
id2=substr(left(put(id,best12.)),1,1);</description>
      <pubDate>Mon, 18 Apr 2011 12:28:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/return-first-digit-of-a-numeric-variable/m-p/52139#M10987</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2011-04-18T12:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: return first digit of a numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/return-first-digit-of-a-numeric-variable/m-p/52140#M10988</link>
      <description>Thanks to everyone for the responses!  Really appreciate all the help!!</description>
      <pubDate>Mon, 18 Apr 2011 17:37:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/return-first-digit-of-a-numeric-variable/m-p/52140#M10988</guid>
      <dc:creator>CharlesR</dc:creator>
      <dc:date>2011-04-18T17:37:06Z</dc:date>
    </item>
    <item>
      <title>Re: return first digit of a numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/return-first-digit-of-a-numeric-variable/m-p/52141#M10989</link>
      <description>Hey KSharp,&lt;BR /&gt;
Is there a way to use this to create a numeric variable instead of a character one?  or do i just need to convert it back to a numeric after i'm done?&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
cr</description>
      <pubDate>Mon, 18 Apr 2011 19:31:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/return-first-digit-of-a-numeric-variable/m-p/52141#M10989</guid>
      <dc:creator>CharlesR</dc:creator>
      <dc:date>2011-04-18T19:31:59Z</dc:date>
    </item>
    <item>
      <title>Re: return first digit of a numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/return-first-digit-of-a-numeric-variable/m-p/52142#M10990</link>
      <description>&amp;gt; Hey KSharp,&lt;BR /&gt;
&amp;gt; Is there a way to use this to create a numeric&lt;BR /&gt;
&amp;gt; variable instead of a character one?  or do i just&lt;BR /&gt;
&amp;gt; need to convert it back to a numeric after i'm done?&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Thanks,&lt;BR /&gt;
&amp;gt; cr&lt;BR /&gt;
&lt;BR /&gt;
Not the best programming practice but if you leave off the length declaration the target variable will default to numeric and you'll get a numeric result and warnings in the log about conversion from string to numeric.</description>
      <pubDate>Mon, 18 Apr 2011 19:54:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/return-first-digit-of-a-numeric-variable/m-p/52142#M10990</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2011-04-18T19:54:18Z</dc:date>
    </item>
    <item>
      <title>Re: return first digit of a numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/return-first-digit-of-a-numeric-variable/m-p/52143#M10991</link>
      <description>See an excellent solution without type conversions at sas-l:&lt;BR /&gt;
&lt;A href="http://www.listserv.uga.edu/cgi-bin/wa?A2=ind0001B&amp;amp;L=sas-l&amp;amp;D=0&amp;amp;P=30671" target="_blank"&gt;http://www.listserv.uga.edu/cgi-bin/wa?A2=ind0001B&amp;amp;L=sas-l&amp;amp;D=0&amp;amp;P=30671&lt;/A&gt;</description>
      <pubDate>Mon, 18 Apr 2011 20:31:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/return-first-digit-of-a-numeric-variable/m-p/52143#M10991</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2011-04-18T20:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: return first digit of a numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/return-first-digit-of-a-numeric-variable/m-p/52144#M10992</link>
      <description>Yes.You  need to convert it back to a numeric after it.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Tue, 19 Apr 2011 00:53:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/return-first-digit-of-a-numeric-variable/m-p/52144#M10992</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-04-19T00:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: return first digit of a numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/return-first-digit-of-a-numeric-variable/m-p/52145#M10993</link>
      <description>That is pure mathematics way.I like it.</description>
      <pubDate>Tue, 19 Apr 2011 01:15:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/return-first-digit-of-a-numeric-variable/m-p/52145#M10993</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-04-19T01:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: return first digit of a numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/return-first-digit-of-a-numeric-variable/m-p/52146#M10994</link>
      <description>This is a format problem.  What you want is the first significant digit of the number.&lt;BR /&gt;
&lt;BR /&gt;
Check David Chapman's NESUG or SUGI paper on user define formats and proc report.  He shows how to create a format to show the first two significant digits.  Just modify that to show the first significant digit.</description>
      <pubDate>Tue, 19 Apr 2011 01:27:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/return-first-digit-of-a-numeric-variable/m-p/52146#M10994</guid>
      <dc:creator>david2010</dc:creator>
      <dc:date>2011-04-19T01:27:19Z</dc:date>
    </item>
  </channel>
</rss>

