<?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 character values to numeric values with informat statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/converting-character-values-to-numeric-values-with-informat/m-p/93503#M19703</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you want to convert the character variables with Y/N to numeric variables with 1/0 then you will need to give them new names.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data want ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;set have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;array _ch &amp;amp;yesnovars ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;array _num &amp;amp;binaryvars;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;do i=1 to dim(_ch);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; if _ch(i)='Y' then _num(i)=1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; else if _ch(i)='N' then _num(i)=0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; else _num(i)=.;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 03 Jun 2013 16:58:15 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2013-06-03T16:58:15Z</dc:date>
    <item>
      <title>converting character values to numeric values with informat statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-values-to-numeric-values-with-informat/m-p/93500#M19700</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'll preface this by saying that I am new to macros.&amp;nbsp; I want to use them because I am working with a sas data set that has over 100 variables, and roughly 40 of them have Yes/No values that I need to convert.&amp;nbsp; I want to convert these Yes/No values to 0/1 values, and I'm having a lot of trouble getting the informat to work.&amp;nbsp; I've created a macro variable (&amp;amp;YesNovars) that contains all of the variables I want to convert.&amp;nbsp; The data step below runs without error, but when I look at the data, nothing has changed.&amp;nbsp; Any help is greatly appreciated!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is what I've tried:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc format library=library;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; invalue $yesno 'Y'='1'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'N'='0'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data bicc.maternal12;&lt;/P&gt;&lt;P&gt;set bicc.maternal10;&lt;/P&gt;&lt;P&gt;attrib &amp;amp;YesNovars informat=$yesno.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Jun 2013 16:34:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-values-to-numeric-values-with-informat/m-p/93500#M19700</guid>
      <dc:creator>sra2131</dc:creator>
      <dc:date>2013-06-03T16:34:04Z</dc:date>
    </item>
    <item>
      <title>Re: converting character values to numeric values with informat statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-values-to-numeric-values-with-informat/m-p/93501#M19701</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Informat does not work on SAS tables like that, as they already have their informat and format. Try use Array() to simply your task:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;A='Y'; B='N';run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array t a--b;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do over t;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if t='Y' then t='1'; else if t='N' then t='0';&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; Haikuo&lt;/P&gt;&lt;P&gt;update: if you intend to use the existing macro variable (which I believe you don't have to), replace a--b with &amp;amp;YesNovars.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Jun 2013 16:46:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-values-to-numeric-values-with-informat/m-p/93501#M19701</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-06-03T16:46:42Z</dc:date>
    </item>
    <item>
      <title>Re: converting character values to numeric values with informat statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-values-to-numeric-values-with-informat/m-p/93502#M19702</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It worked! Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Jun 2013 16:51:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-values-to-numeric-values-with-informat/m-p/93502#M19702</guid>
      <dc:creator>sra2131</dc:creator>
      <dc:date>2013-06-03T16:51:04Z</dc:date>
    </item>
    <item>
      <title>Re: converting character values to numeric values with informat statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-values-to-numeric-values-with-informat/m-p/93503#M19703</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you want to convert the character variables with Y/N to numeric variables with 1/0 then you will need to give them new names.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data want ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;set have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;array _ch &amp;amp;yesnovars ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;array _num &amp;amp;binaryvars;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;do i=1 to dim(_ch);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; if _ch(i)='Y' then _num(i)=1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; else if _ch(i)='N' then _num(i)=0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; else _num(i)=.;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Jun 2013 16:58:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-values-to-numeric-values-with-informat/m-p/93503#M19703</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-06-03T16:58:15Z</dc:date>
    </item>
    <item>
      <title>Re: converting character values to numeric values with informat statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-values-to-numeric-values-with-informat/m-p/93504#M19704</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you, Tom.&lt;/P&gt;&lt;P&gt;It really helps &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Dec 2013 13:48:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-values-to-numeric-values-with-informat/m-p/93504#M19704</guid>
      <dc:creator>Hyoun</dc:creator>
      <dc:date>2013-12-03T13:48:29Z</dc:date>
    </item>
  </channel>
</rss>

