<?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 Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-Y-N-data-to-0-1-data/m-p/305010#M65014</link>
    <description>&lt;P&gt;As Y/N are characters you need to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; If flag = "Y" then flag = "1" else flag = "0";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also you can create a format to display "Y" as "1" and "N" as "0", and eliminate change of data.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 17 Oct 2016 08:26:42 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2016-10-17T08:26:42Z</dc:date>
    <item>
      <title>How to convert Y/N data to 0/1 data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-Y-N-data-to-0-1-data/m-p/305005#M65011</link>
      <description>&lt;P&gt;I have a single variable in a dataset that has y/n values and need to be changed to 1/0 values.&amp;nbsp; I have tried and if/then statement, if/then do, and I cannot get anything to work.&amp;nbsp; Does anyone have any suggestions?&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 08:18:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-Y-N-data-to-0-1-data/m-p/305005#M65011</guid>
      <dc:creator>BoboTheFool</dc:creator>
      <dc:date>2016-10-17T08:18:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert Y/N data to 0/1 data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-Y-N-data-to-0-1-data/m-p/305009#M65013</link>
      <description>&lt;P&gt;IF/THEN/ELSE is one way.&lt;/P&gt;
&lt;P&gt;If you wish to have your 1/0 as NUM, be sure to store it in a new variable.&lt;/P&gt;
&lt;P&gt;What problems are you experienceing?&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 08:25:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-Y-N-data-to-0-1-data/m-p/305009#M65013</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-10-17T08:25: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-Programming/How-to-convert-Y-N-data-to-0-1-data/m-p/305010#M65014</link>
      <description>&lt;P&gt;As Y/N are characters you need to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; If flag = "Y" then flag = "1" else flag = "0";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also you can create a format to display "Y" as "1" and "N" as "0", and eliminate change of data.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 08:26:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-Y-N-data-to-0-1-data/m-p/305010#M65014</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-10-17T08:26: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-Programming/How-to-convert-Y-N-data-to-0-1-data/m-p/305012#M65015</link>
      <description>&lt;P&gt;First of all, you cannot change the variable "in place", as it is of type character and will stay that way.&lt;/P&gt;
&lt;P&gt;There are several ways, all involve replacing the old variable with a new one:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have (rename=(variable=oldvar));
if oldvar = 'N' then variable = 0; else variable = 1;
drop oldvar;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or (to take care of missing values):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have (rename=(variable=oldvar));
select (oldvar);
  when ('Y') variable = 1;
  when ('N') variable = 0;
  otherwise;
end;
drop oldvar;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or you might create a custom invalue informat with proc format, and use that in an input() function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
invalue infmt
  'Y' = 1
  'N' = 0
  other = .
;
run;

data want2;
set have (rename=(variable=oldvar));
variable = input(oldvar,infmt.);
drop oldvar;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Oct 2016 08:27:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-Y-N-data-to-0-1-data/m-p/305012#M65015</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-10-17T08:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert Y/N data to 0/1 data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-Y-N-data-to-0-1-data/m-p/305016#M65016</link>
      <description>&lt;P&gt;As others have noted, format is probably the simplest in the this instance:&lt;/P&gt;
&lt;PRE&gt;proc format;
  value $yn
    "Y"=1
    "N"=0;
run;

data want;
  set have;
  format ynvariable $yn.;
run;&lt;/PRE&gt;
&lt;P&gt;Personally I tend to avoid proprietary file formats - catalogs for instance all broke due to the 32bit/64bit split. &amp;nbsp;So in most coding cases I would have one character field, possibly one numeric field (if the data can be numeric) and one coded field. &amp;nbsp;Then you have the original data and converted data and it can all be plain file. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 08:43:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-Y-N-data-to-0-1-data/m-p/305016#M65016</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-10-17T08:43:48Z</dc:date>
    </item>
  </channel>
</rss>

