<?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: Numeric Being Converted to Character! How to Prevent? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Numeric-Being-Converted-to-Character-How-to-Prevent/m-p/810270#M319526</link>
    <description>&lt;P&gt;You want an INFORMAT not a FORMAT.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;...
retain FMTNAME 'Fmt' type 'I';
...
CitShare=INPUT(market,Fmt.);
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;FORMATs convert values to text.&amp;nbsp; INFORMATs convert text to values.&lt;/P&gt;
&lt;P&gt;Numeric formats convert numeric&amp;nbsp;values to text.&lt;/P&gt;
&lt;P&gt;Character formats convert character values to text.&lt;/P&gt;
&lt;P&gt;Numeric informats convert text to numeric values .&lt;/P&gt;
&lt;P&gt;Character informats convert text to character values .&lt;/P&gt;</description>
    <pubDate>Wed, 27 Apr 2022 19:56:30 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-04-27T19:56:30Z</dc:date>
    <item>
      <title>Numeric Being Converted to Character! How to Prevent?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-Being-Converted-to-Character-How-to-Prevent/m-p/810221#M319503</link>
      <description>&lt;P&gt;I create a format using proc format cntlin:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data Fmt(keep=FMTNAME TYPE START LABEL HLO);
	retain FMTNAME 'Fmt' type 'C';
	set dataset END=EOF;
	where CitShare ne .;
	start=market;
	label=CitShare;
	output;
	if EOF;
	HLO='O';
	LABEL='.';
	output;
run;

proc format cntlin=Fmt library=work;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Everything looks good. The label variable in the Fmt dataset is numeric.&lt;BR /&gt;But later when I use the format, it converts to numeric.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data cit_join;
	set cit_markets;
	CitShare=put(market,$Fmt.);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;cit_join has CitShare as a character variable.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;What am I doing wrong? How can I make it stay numeric?&lt;BR /&gt;&lt;BR /&gt;I even try to then convert it to numeric and it doesn't work:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data join;
set join;
	CitShare = input(CitShare, best32.);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;log reads:&amp;nbsp;&lt;BR /&gt;NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).&lt;BR /&gt;31:13&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2022 16:49:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-Being-Converted-to-Character-How-to-Prevent/m-p/810221#M319503</guid>
      <dc:creator>Paige1</dc:creator>
      <dc:date>2022-04-27T16:49:35Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric Being Converted to Character! How to Prevent?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-Being-Converted-to-Character-How-to-Prevent/m-p/810251#M319513</link>
      <description>&lt;P&gt;The PUT function ALWAYS returns a character value.&amp;nbsp; That's it's job.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to convert a character value to a numeric value, you need to use the INPUT function with a numeric informat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could use PROC format to create a numeric informat, or you could use your current character format like (untested):&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cit_join;
	set cit_markets;
	CitShare=input(put(market,$Fmt.),best32.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Your second attempt at this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data join;
set join;
	CitShare = input(CitShare, best32.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;likely didn't work because CitShare already existed in the dataset join as a character variable.&amp;nbsp; So the input function returned a numeric value, but then SAS had to force that value into a character variable so it converted the numeric value to character, and threw the NOTE you see in the log.&amp;nbsp; You can't actually *change* the type of a variable in SAS.&amp;nbsp; Your second approach would have worked if you renamed the character variable when you read it in, something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data myjoin; *bad idea to read and write the same dataset, so I changed this name;
set join (rename=(CitShare=_CitShare));
	CitShare = input(_CitShare, best32.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2022 17:58:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-Being-Converted-to-Character-How-to-Prevent/m-p/810251#M319513</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-04-27T17:58:14Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric Being Converted to Character! How to Prevent?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-Being-Converted-to-Character-How-to-Prevent/m-p/810270#M319526</link>
      <description>&lt;P&gt;You want an INFORMAT not a FORMAT.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;...
retain FMTNAME 'Fmt' type 'I';
...
CitShare=INPUT(market,Fmt.);
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;FORMATs convert values to text.&amp;nbsp; INFORMATs convert text to values.&lt;/P&gt;
&lt;P&gt;Numeric formats convert numeric&amp;nbsp;values to text.&lt;/P&gt;
&lt;P&gt;Character formats convert character values to text.&lt;/P&gt;
&lt;P&gt;Numeric informats convert text to numeric values .&lt;/P&gt;
&lt;P&gt;Character informats convert text to character values .&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2022 19:56:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-Being-Converted-to-Character-How-to-Prevent/m-p/810270#M319526</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-27T19:56:30Z</dc:date>
    </item>
  </channel>
</rss>

