<?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: How to convert Y/N data to 0/1 data? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-convert-Y-N-data-to-0-1-data/m-p/181532#M46251</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since the existing variables are character they can't be made into numeric but new variables with the numeric values can be created.&lt;/P&gt;&lt;P&gt;OR if you read the data from a text file that could be read into numeric.&lt;/P&gt;&lt;P&gt;A custom informat is the easiest.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc format;&lt;/P&gt;&lt;P&gt;invalue YN (upcase)&lt;/P&gt;&lt;P&gt;'Y' = 1&lt;/P&gt;&lt;P&gt;'N' = 0&lt;/P&gt;&lt;P&gt;other = .; /* this assigns any unexpected characters to missing */&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* best to create bunch of variables and assigning values with an array*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array c &amp;lt; list name of existing variables with YN values here&amp;gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array New &amp;lt;a list of corresponding new variables here&amp;gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do I=1 to dim(c);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; New&lt;I&gt; = input(c&lt;I&gt;,YN.);&lt;/I&gt;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I were reading the data from a text file I would read those values after assigning YN as the informat.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 21 Nov 2014 17:07:43 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2014-11-21T17:07:43Z</dc:date>
    <item>
      <title>How to convert Y/N data to 0/1 data?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-convert-Y-N-data-to-0-1-data/m-p/181531#M46250</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have multiple variables in my dataset that have Y/N data but I need to convert it to 0/1 data for analysis. Does anyone know a macro or a code that would help with this conversion of the variables with Y/N data?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Nov 2014 16:38:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-convert-Y-N-data-to-0-1-data/m-p/181531#M46250</guid>
      <dc:creator>WillS_</dc:creator>
      <dc:date>2014-11-21T16:38:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert Y/N data to 0/1 data?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-convert-Y-N-data-to-0-1-data/m-p/181532#M46251</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since the existing variables are character they can't be made into numeric but new variables with the numeric values can be created.&lt;/P&gt;&lt;P&gt;OR if you read the data from a text file that could be read into numeric.&lt;/P&gt;&lt;P&gt;A custom informat is the easiest.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc format;&lt;/P&gt;&lt;P&gt;invalue YN (upcase)&lt;/P&gt;&lt;P&gt;'Y' = 1&lt;/P&gt;&lt;P&gt;'N' = 0&lt;/P&gt;&lt;P&gt;other = .; /* this assigns any unexpected characters to missing */&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* best to create bunch of variables and assigning values with an array*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array c &amp;lt; list name of existing variables with YN values here&amp;gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array New &amp;lt;a list of corresponding new variables here&amp;gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do I=1 to dim(c);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; New&lt;I&gt; = input(c&lt;I&gt;,YN.);&lt;/I&gt;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I were reading the data from a text file I would read those values after assigning YN as the informat.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Nov 2014 17:07:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-convert-Y-N-data-to-0-1-data/m-p/181532#M46251</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-11-21T17:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert Y/N data to 0/1 data?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-convert-Y-N-data-to-0-1-data/m-p/181533#M46252</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Nov 2014 17:17:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-convert-Y-N-data-to-0-1-data/m-p/181533#M46252</guid>
      <dc:creator>WillS_</dc:creator>
      <dc:date>2014-11-21T17:17:47Z</dc:date>
    </item>
  </channel>
</rss>

