<?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: proc sql: equivalent of convert integer to char with trailing zeros in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-equivalent-of-convert-integer-to-char-with-trailing/m-p/269323#M53355</link>
    <description>&lt;P&gt;First - I have just edited question - I had program_id not data_id in the SQL server code. &amp;nbsp;However using your suggestions I get the following error (and a similar error when I use the INPUT function):&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;ERROR: Function ROUND requires a numeric expression as argument 1.&lt;BR /&gt;ERROR: Expression using equals (=) has components that are of different data types.&lt;BR /&gt;&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 10 May 2016 03:15:04 GMT</pubDate>
    <dc:creator>mduarte</dc:creator>
    <dc:date>2016-05-10T03:15:04Z</dc:date>
    <item>
      <title>proc sql: equivalent of convert integer to char with trailing zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-equivalent-of-convert-integer-to-char-with-trailing/m-p/269320#M53353</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have an id&amp;nbsp;stored as '14344.000000000000000000' in one table and as 14344 in another.&lt;/P&gt;&lt;P&gt;How can I use proc sql to match them correctly for the following circumstances&lt;/P&gt;&lt;PRE&gt;data one;&lt;BR /&gt;input data_id 8.;&lt;BR /&gt;datalines;&lt;BR /&gt;14344&lt;BR /&gt;0&lt;BR /&gt;. &lt;BR /&gt;. &lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data two;&lt;BR /&gt;input data_id $1-27 description $ 28-47;&lt;BR /&gt;datalines;&lt;BR /&gt;14344.00000000000000000000 my_data_description&lt;BR /&gt;not_like_a_number1 another_description&lt;BR /&gt;not_like_a_number2 description_2&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;/*incorrect*/&lt;BR /&gt;proc sql;&lt;BR /&gt; select * from one&lt;BR /&gt; left join two on one.data_id = input(two.data_id, 8.);&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;/*incorrect, convert char to numeric and use case statement: Have multiple lines for data_one.data_id = .*/&lt;BR /&gt;select &lt;BR /&gt; one.*,&lt;BR /&gt; case when one.data_id NE . then two.description else '' end as description&lt;BR /&gt; from one&lt;BR /&gt; left join two on one.data_id = input(two.data_id, 8.);&lt;BR /&gt;run; &lt;BR /&gt;&lt;BR /&gt;quit; &lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;Desired output&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;data_id &amp;nbsp;description&lt;/P&gt;&lt;P&gt;14344 &amp;nbsp;my_data_description&lt;/P&gt;&lt;P&gt;0&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that the following works in SQL server and is what I want to replicate using proc sql&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select *
from one
left join two on convert(varchar(100),convert(numeric(38,20),one.data_id)) =  two.data_id;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2016 03:13:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-equivalent-of-convert-integer-to-char-with-trailing/m-p/269320#M53353</guid>
      <dc:creator>mduarte</dc:creator>
      <dc:date>2016-05-10T03:13:21Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: equivalent of convert integer to char with trailing zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-equivalent-of-convert-integer-to-char-with-trailing/m-p/269321#M53354</link>
      <description>&lt;P&gt;You could round it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;round(one.data_id, 1) = round(two.program_id, 1)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or to convert to Char&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input(one.data_id, 8.) = input(two.program_id, 8.)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 May 2016 03:09:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-equivalent-of-convert-integer-to-char-with-trailing/m-p/269321#M53354</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-05-10T03:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: equivalent of convert integer to char with trailing zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-equivalent-of-convert-integer-to-char-with-trailing/m-p/269323#M53355</link>
      <description>&lt;P&gt;First - I have just edited question - I had program_id not data_id in the SQL server code. &amp;nbsp;However using your suggestions I get the following error (and a similar error when I use the INPUT function):&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;ERROR: Function ROUND requires a numeric expression as argument 1.&lt;BR /&gt;ERROR: Expression using equals (=) has components that are of different data types.&lt;BR /&gt;&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2016 03:15:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-equivalent-of-convert-integer-to-char-with-trailing/m-p/269323#M53355</guid>
      <dc:creator>mduarte</dc:creator>
      <dc:date>2016-05-10T03:15:04Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: equivalent of convert integer to char with trailing zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-equivalent-of-convert-integer-to-char-with-trailing/m-p/269325#M53356</link>
      <description>&lt;P&gt;The way you initially stated the problem, I assumed both were numeric and you were having numeric precision issues.&lt;/P&gt;
&lt;P&gt;Given your errors, it appears that's not the case.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like&amp;nbsp;one is character and one is numeric, for the one that is character remove the input function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the other add the input function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given the error you posted I can't tell which is which, so play around until you get it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this I would imagine - combine the two above.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input(round(numeric_var, 1), 8.) = char_var&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 May 2016 03:23:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-equivalent-of-convert-integer-to-char-with-trailing/m-p/269325#M53356</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-05-10T03:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: equivalent of convert integer to char with trailing zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-equivalent-of-convert-integer-to-char-with-trailing/m-p/269334#M53358</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; - the two data examples (sets named one and two show the format of the data exactly as is in the real life example... ) &amp;nbsp;perhaps you only see the last code chunk in the original question, and not the first one?&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2016 04:46:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-equivalent-of-convert-integer-to-char-with-trailing/m-p/269334#M53358</guid>
      <dc:creator>mduarte</dc:creator>
      <dc:date>2016-05-10T04:46:13Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: equivalent of convert integer to char with trailing zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-equivalent-of-convert-integer-to-char-with-trailing/m-p/269338#M53359</link>
      <description>&lt;P&gt;I'm apologize, I didn't read your question thoroughly. You did post sample input data and output.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The issue is when you do any conversion the character values get converted to missing and then match with the missing in your data. In my solution I've coded them to -9999 instead. You'll need to decide on a solution that works for your data, but hopefully this helps you get started.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input data_id 8.;
datalines;
14344
0
. 
. 
;
run;

data two;
input data_id $1-27 description $ 28-47;
datalines;
14344.00000000000000000000 my_data_description
not_like_a_number1 another_description
not_like_a_number2 description_2
;
run;

proc sql;
create table want as
select distinct a.*, b.description
from one as a
left join two as b
on round(a.data_id, 1) = case when anyalpha(b.data_id) then -99999
                              else round(input(b.data_id, 8.), 1) end;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 May 2016 05:03:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-equivalent-of-convert-integer-to-char-with-trailing/m-p/269338#M53359</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-05-10T05:03:33Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: equivalent of convert integer to char with trailing zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-equivalent-of-convert-integer-to-char-with-trailing/m-p/269339#M53360</link>
      <description>I'm with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; here. You are definitely trying to round a char variable. Play around, meaning try to get themy in the same format separately, and then do the join.</description>
      <pubDate>Tue, 10 May 2016 05:06:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-equivalent-of-convert-integer-to-char-with-trailing/m-p/269339#M53360</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-05-10T05:06:35Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: equivalent of convert integer to char with trailing zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-equivalent-of-convert-integer-to-char-with-trailing/m-p/269340#M53361</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; - okay - I had been hoping for a generic solution like that in SQL Server (the convert(varchar(100), convert(numeric(38,20), varname) without the need for a case statement. &amp;nbsp;Your solution in the end is similar to my second sql statement except you have the case statement on the on clause and not in the select and you use distinct. &amp;nbsp;Still an improvement !!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH&lt;/a&gt; - thanks for your input (genuinely and without&amp;nbsp;sarcasm), however in this instance and in my defense I wasn't actually trying to round a character - only showing Reeza that his first solution wasn't viable....&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2016 05:17:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-equivalent-of-convert-integer-to-char-with-trailing/m-p/269340#M53361</guid>
      <dc:creator>mduarte</dc:creator>
      <dc:date>2016-05-10T05:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: equivalent of convert integer to char with trailing zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-equivalent-of-convert-integer-to-char-with-trailing/m-p/269341#M53362</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67853"&gt;@mduarte﻿&lt;/a&gt;&amp;nbsp;her &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There may be another way, probably convert both to character, but you'd still have to convert the number and strip the decimal portion first. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2016 05:24:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-equivalent-of-convert-integer-to-char-with-trailing/m-p/269341#M53362</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-05-10T05:24:16Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: equivalent of convert integer to char with trailing zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-equivalent-of-convert-integer-to-char-with-trailing/m-p/269345#M53364</link>
      <description>&lt;P&gt;Or do you like Perl Regular Expression ?&lt;/P&gt;
&lt;P&gt;NOTE: if data_id in table ONE has decimal. you need change &lt;SPAN&gt; Perl Regular Expression.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input data_id 8.;
datalines;
14344
0
. 
. 
;
run;

data two;
input data_id $1-27 description $ 28-47;
datalines;
14344.00000000000000000000 my_data_description
not_like_a_number1 another_description
not_like_a_number2 description_2
;
run;

/*incorrect*/&lt;BR /&gt;options missing=' ';
proc sql;
 select * from one
 left join two on 
  prxmatch(cats('/^',one.data_id,'(\.0*)?$/'),strip(two.data_id));
quit; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2016 06:09:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-equivalent-of-convert-integer-to-char-with-trailing/m-p/269345#M53364</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-05-10T06:09:39Z</dc:date>
    </item>
  </channel>
</rss>

