<?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: Converting numeric to character variable in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Converting-numeric-to-character-variable/m-p/826071#M35253</link>
    <description>&lt;P&gt;Leave the variable alone a create a custom format with the current values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data example;
   input sex;
datalines;
0
1
;

proc format;
value sex
0='Female'
1='Male'
;

proc print data=example noobs;
   var sex;
   format sex sex. ;
run;&lt;/PRE&gt;
&lt;P&gt;If the variable may have missing values I would add appropriate format such as&lt;/P&gt;
&lt;PRE&gt;proc format;
value sex
0='Femaie'
1='Male'
.= 'Missing'
;
&lt;/PRE&gt;</description>
    <pubDate>Thu, 28 Jul 2022 22:48:22 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-07-28T22:48:22Z</dc:date>
    <item>
      <title>Converting numeric to character variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-numeric-to-character-variable/m-p/826069#M35251</link>
      <description>&lt;P&gt;Hi All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a numeric sex variable with values of 0 or 1 (0=female, 1=male).&amp;nbsp; I want to convert this to character variable so I can add the aforementioned format in a proc format statement.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The below code does not make a new variable "sex_c", and you can see in the proc contents output, sex is still showing as numeric.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's my code:&lt;/P&gt;&lt;PRE&gt;Data datasets.redcap_pde1;
	set datasets.redcap_pde0;
	Sex_c=PUT(sex,8.);
	Drop sex_c;
run;

Results:

Obs	Sex
1	0
2	1
3	1
4	1
5	1
6	0
7	0

Proc contents:
                     Variables in Creation Order
#	Variable	Type	Len	Format	Informat	Label
6	  Sex	      Num	  8	   15.	 	          Sex&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Jul 2022 22:02:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-numeric-to-character-variable/m-p/826069#M35251</guid>
      <dc:creator>kristiepauly</dc:creator>
      <dc:date>2022-07-28T22:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: Converting numeric to character variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-numeric-to-character-variable/m-p/826070#M35252</link>
      <description>&lt;P&gt;Why do you want is as character?&lt;/P&gt;
&lt;P&gt;I think the format should be $8.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Quick rules of thumb, for PUT use the format you want to see in the output.&lt;/P&gt;
&lt;P&gt;For input, use the informat the variable currently has.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're showing the format for Sex, not SEX_C which should be the character variable which you've dropped.....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 22:12:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-numeric-to-character-variable/m-p/826070#M35252</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-07-28T22:12:42Z</dc:date>
    </item>
    <item>
      <title>Re: Converting numeric to character variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-numeric-to-character-variable/m-p/826071#M35253</link>
      <description>&lt;P&gt;Leave the variable alone a create a custom format with the current values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data example;
   input sex;
datalines;
0
1
;

proc format;
value sex
0='Female'
1='Male'
;

proc print data=example noobs;
   var sex;
   format sex sex. ;
run;&lt;/PRE&gt;
&lt;P&gt;If the variable may have missing values I would add appropriate format such as&lt;/P&gt;
&lt;PRE&gt;proc format;
value sex
0='Femaie'
1='Male'
.= 'Missing'
;
&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Jul 2022 22:48:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-numeric-to-character-variable/m-p/826071#M35253</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-07-28T22:48:22Z</dc:date>
    </item>
    <item>
      <title>Re: Converting numeric to character variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-numeric-to-character-variable/m-p/826074#M35254</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;Thank you again.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is frustrating. I've been messing with this for hours. I originally had what you suggested, except for the&amp;nbsp; . = "missing" and it didn't work, hence why I thought I needed to change to character to see it.&amp;nbsp; It doesn't make sense to me why adding the above line of code would all of a sudden make everything work? I didn't really care about labeling the missing data as such and figured it would just output a &amp;lt;period&amp;gt; if there wasn't a 0 or 1 in the column and I would therefore know that . = missing.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 23:47:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-numeric-to-character-variable/m-p/826074#M35254</guid>
      <dc:creator>kristiepauly</dc:creator>
      <dc:date>2022-07-28T23:47:36Z</dc:date>
    </item>
    <item>
      <title>Re: Converting numeric to character variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-numeric-to-character-variable/m-p/826075#M35255</link>
      <description>&lt;P&gt;I didn't really want to make it a character variable. I thought I had to, to get the format to work correctly.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It was my understanding PUT is used when going from numeric to character and INPUT is used when going from character to numeric?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 23:49:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-numeric-to-character-variable/m-p/826075#M35255</guid>
      <dc:creator>kristiepauly</dc:creator>
      <dc:date>2022-07-28T23:49:53Z</dc:date>
    </item>
  </channel>
</rss>

