<?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: Conditional converting variable type from numeric to char in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditional-converting-variable-type-from-numeric-to-char/m-p/515034#M138937</link>
    <description>&lt;P&gt;If you use the put() function, the type of the first argument determines the typeof the format. Since snif is character, SAS needs a character format, and goes looking for that, but doesn't find one.&lt;/P&gt;</description>
    <pubDate>Wed, 21 Nov 2018 09:57:19 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-11-21T09:57:19Z</dc:date>
    <item>
      <title>Conditional converting variable type from numeric to char</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-converting-variable-type-from-numeric-to-char/m-p/515002#M138922</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;What is the reason for getting error in the following code.&lt;/P&gt;
&lt;P&gt;error 484&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE 484-185: Format $BEST was not found or could not be loaded.&lt;/P&gt;
&lt;P&gt;How can I modify the code i order to fix the error?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 
***Conditional converting variable type***;
***find out if a variable is character or numeric***;
*** If it is Numeric then I need to convert it to Char;
*** If it is Char then converting is not needed***;
Data a;
input x;
cards;
111
222
333
;
run;

Data aa;
set a;
type=vtype(x);
IF type='N' then xx=compress(put(x,best12.));
else xx=compress(x);
run;



Data b;
input x $;
cards;
111
222
333
;
run;

Data bb;
set b;
type=vtype(x);
IF type='N' then xx=compress(put(x,best12.));
else xx=compress(x);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Nov 2018 06:42:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-converting-variable-type-from-numeric-to-char/m-p/515002#M138922</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-11-21T06:42:42Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional converting variable type from numeric to char</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-converting-variable-type-from-numeric-to-char/m-p/515003#M138923</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I found solution but still didn't understand why the error appear.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;***Conditional converting veraible type***;
***find out if a variable is character or numeric***;
*** If it is character then I need to convert it to Numeric;
*** If it is Numeric then converting is not needed***;
Data tbl1;
input snif;
cards;
111
222
333
;
run;

Data tbl1_new (drop=snif);
set tbl1;
type=vtype(snif);
IF type ne 'N' then snif_num=input(snif,3.);
/*If snif is char then we convert it to numeric*/
else snif_num=snif;
run;



Data tbl2;
input snif $;
cards;
111
222
333
;
run;
Data tbl2_new (drop=snif);
set tbl2;
type=vtype(snif);
IF type ne 'N' then snif_num=input(snif,3.);
/*If snif is char then we convert it to numeric*/
else snif_num=snif;
run;

/*https://communities.sas.com/t5/SAS-Studio/Check-variable-type-then-convert-it-to-character/td-p/427603*/



***Conditional converting varaible type***;
***find out if a variable is character or numeric***;
*** If it is Numeric then I need to convert it to Char;
*** If it is Char then converting is not needed***;
***Here we must use fnunction vvalue,which create a character version of OLDVAR***;
Data a;
input x;
cards;
111
222
333
;
run;
Data aa;
set a;
  length xx $3 ;
  xx=compress(vvalue(x));
  drop x ;
  rename xx=x;
run;



Data b;
input x $;
cards;
111
222
333
;
run;
Data bb;
set b;
  length xx $3 ;
  xx=compress(vvalue(x));
  drop x ;
  rename xx=x;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Nov 2018 06:52:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-converting-variable-type-from-numeric-to-char/m-p/515003#M138923</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-11-21T06:52:33Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional converting variable type from numeric to char</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-converting-variable-type-from-numeric-to-char/m-p/515005#M138924</link>
      <description>&lt;P&gt;When you use "input x;" and there is no other statement to define x as character type&lt;/P&gt;
&lt;P&gt;then&amp;nbsp;x is by default numeric and you can code "xx=put(x,best12.)" to covert its value to char type in xx.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you use "input x $;" - you &lt;STRONG&gt;already&lt;/STRONG&gt; defined x as &lt;STRONG&gt;character&lt;/STRONG&gt; type therefor&lt;/P&gt;
&lt;P&gt;you cannot use put function with numeric format like best.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can check a &lt;STRONG&gt;variable&lt;/STRONG&gt; type by vtype() function when you don't know its &lt;STRONG&gt;type&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;It doesn't check the variable's value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Nov 2018 07:05:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-converting-variable-type-from-numeric-to-char/m-p/515005#M138924</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-11-21T07:05:42Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional converting variable type from numeric to char</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-converting-variable-type-from-numeric-to-char/m-p/515034#M138937</link>
      <description>&lt;P&gt;If you use the put() function, the type of the first argument determines the typeof the format. Since snif is character, SAS needs a character format, and goes looking for that, but doesn't find one.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Nov 2018 09:57:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-converting-variable-type-from-numeric-to-char/m-p/515034#M138937</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-11-21T09:57:19Z</dc:date>
    </item>
  </channel>
</rss>

