<?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 Length of character variable created from numeric in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Length-of-character-variable-created-from-numeric/m-p/493909#M130054</link>
    <description>&lt;P&gt;I have a numeric variable coded as 0/1&lt;/P&gt;&lt;P&gt;I want to create a character&amp;nbsp;variable that would allow at least 11 characters&amp;nbsp;in the word, can someone guide the best way to code this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;drug&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;cards&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token number"&gt;0&lt;/SPAN&gt;
&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;  
&lt;SPAN class="token number"&gt;0;&lt;/SPAN&gt;  
&lt;SPAN class="token procnames"&gt;Run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I want to create a character&amp;nbsp;variable such as&amp;nbsp;&lt;/P&gt;&lt;P&gt;if drug1=1 then ch= 'healthinsurance'&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 09 Sep 2018 15:07:12 GMT</pubDate>
    <dc:creator>lillymaginta</dc:creator>
    <dc:date>2018-09-09T15:07:12Z</dc:date>
    <item>
      <title>Length of character variable created from numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Length-of-character-variable-created-from-numeric/m-p/493909#M130054</link>
      <description>&lt;P&gt;I have a numeric variable coded as 0/1&lt;/P&gt;&lt;P&gt;I want to create a character&amp;nbsp;variable that would allow at least 11 characters&amp;nbsp;in the word, can someone guide the best way to code this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;drug&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;cards&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token number"&gt;0&lt;/SPAN&gt;
&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;  
&lt;SPAN class="token number"&gt;0;&lt;/SPAN&gt;  
&lt;SPAN class="token procnames"&gt;Run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I want to create a character&amp;nbsp;variable such as&amp;nbsp;&lt;/P&gt;&lt;P&gt;if drug1=1 then ch= 'healthinsurance'&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Sep 2018 15:07:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Length-of-character-variable-created-from-numeric/m-p/493909#M130054</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2018-09-09T15:07:12Z</dc:date>
    </item>
    <item>
      <title>Re: Length of character variable created from numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Length-of-character-variable-created-from-numeric/m-p/493926#M130065</link>
      <description>&lt;P&gt;Not sure i understand you req, do you mean assigning length for your char?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input drug;&lt;BR /&gt;cards;&lt;BR /&gt;0&lt;BR /&gt;1 &lt;BR /&gt;; &lt;BR /&gt;Run;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;&lt;STRONG&gt;length ch $20;&lt;/STRONG&gt;&lt;BR /&gt;if drug=1 then ch= 'healthinsurance' ;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Sep 2018 16:54:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Length-of-character-variable-created-from-numeric/m-p/493926#M130065</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-09T16:54:22Z</dc:date>
    </item>
    <item>
      <title>Re: Length of character variable created from numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Length-of-character-variable-created-from-numeric/m-p/493938#M130074</link>
      <description>&lt;P&gt;The same way you would define the length for any variable in your data set. Use the LENGTH statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  length drug 8 ch $12 ;
  input drug;
  if drug then ch= 'healthinsurance' ;
cards;
0
1
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Sep 2018 17:52:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Length-of-character-variable-created-from-numeric/m-p/493938#M130074</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-09-09T17:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: Length of character variable created from numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Length-of-character-variable-created-from-numeric/m-p/493939#M130075</link>
      <description>&lt;P&gt;Define a format with your translations, and the resulting variable (when the format is used in a put() function) will have the appropriate length.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value mytrans
  1 = 'healthinsurance'
  0 = 'other'
;
run;

data want;
input numvar;
charvar = pu(numvar,mytrans.);
cards;
0
1
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 09 Sep 2018 17:59:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Length-of-character-variable-created-from-numeric/m-p/493939#M130075</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-09T17:59:49Z</dc:date>
    </item>
    <item>
      <title>Re: Length of character variable created from numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Length-of-character-variable-created-from-numeric/m-p/494167#M130182</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Define a format with your translations, and the resulting variable (when the format is used in a put() function) will have the appropriate length.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value mytrans
  1 = 'healthinsurance'
  0 = 'other'
;
run;

data want;
input numvar;
charvar = pu(numvar,mytrans.);
cards;
0
1
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Or just use the FORMAT to display the value without creating another variable.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Sep 2018 15:36:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Length-of-character-variable-created-from-numeric/m-p/494167#M130182</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-09-10T15:36:29Z</dc:date>
    </item>
  </channel>
</rss>

