<?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 replace 1/0 with Y/N in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/replace-1-0-with-Y-N/m-p/611730#M178352</link>
    <description>I have a dataset with multiple columns with name starting ind_ (eg ind_name, ind_adr,ind_sal) and the values are either 1 or 0 . I will need to convert those values to Y or N with the variable names keeping same.&lt;BR /&gt;&lt;BR /&gt;I tried using proc format and the columns showed correct values of Y or N but they were numeric.&lt;BR /&gt;&lt;BR /&gt;Is there a way I can achieve that by also changing the data type to character?&lt;BR /&gt;&lt;BR /&gt;Thanks in advance</description>
    <pubDate>Fri, 13 Dec 2019 21:11:58 GMT</pubDate>
    <dc:creator>nickspencer</dc:creator>
    <dc:date>2019-12-13T21:11:58Z</dc:date>
    <item>
      <title>replace 1/0 with Y/N</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-1-0-with-Y-N/m-p/611730#M178352</link>
      <description>I have a dataset with multiple columns with name starting ind_ (eg ind_name, ind_adr,ind_sal) and the values are either 1 or 0 . I will need to convert those values to Y or N with the variable names keeping same.&lt;BR /&gt;&lt;BR /&gt;I tried using proc format and the columns showed correct values of Y or N but they were numeric.&lt;BR /&gt;&lt;BR /&gt;Is there a way I can achieve that by also changing the data type to character?&lt;BR /&gt;&lt;BR /&gt;Thanks in advance</description>
      <pubDate>Fri, 13 Dec 2019 21:11:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-1-0-with-Y-N/m-p/611730#M178352</guid>
      <dc:creator>nickspencer</dc:creator>
      <dc:date>2019-12-13T21:11:58Z</dc:date>
    </item>
    <item>
      <title>Re: replace 1/0 with Y/N</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-1-0-with-Y-N/m-p/611733#M178354</link>
      <description>&lt;P&gt;You can't change the type of an existing SAS variable, you have to create a new variable based on the old one. One common trick is to rename the variable you want to switch like below, then recreate the original variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value yn
  0='N'
  1='Y';
run;

data want;
  drop tmp_:;
  set have (rename = (MyYesNoVar = tmp_MyYesNoVar));
  MyYesNoVar = put(tmp_MyYesNoVar, yn.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Dec 2019 21:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-1-0-with-Y-N/m-p/611733#M178354</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-12-13T21:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: replace 1/0 with Y/N</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-1-0-with-Y-N/m-p/611736#M178356</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt; I have multiple variables to change. Is there a way to achieve this at a time for multiple variables ?</description>
      <pubDate>Fri, 13 Dec 2019 21:26:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-1-0-with-Y-N/m-p/611736#M178356</guid>
      <dc:creator>nickspencer</dc:creator>
      <dc:date>2019-12-13T21:26:02Z</dc:date>
    </item>
    <item>
      <title>Re: replace 1/0 with Y/N</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-1-0-with-Y-N/m-p/611739#M178357</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/206798"&gt;@nickspencer&lt;/a&gt;&amp;nbsp; - Yes. An array in the example code I posted could do this. How many variables do you want to change?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 21:32:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-1-0-with-Y-N/m-p/611739#M178357</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-12-13T21:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: replace 1/0 with Y/N</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-1-0-with-Y-N/m-p/611740#M178358</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt; there are 15 variables but they all start with the name ind_</description>
      <pubDate>Fri, 13 Dec 2019 21:45:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-1-0-with-Y-N/m-p/611740#M178358</guid>
      <dc:creator>nickspencer</dc:creator>
      <dc:date>2019-12-13T21:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: replace 1/0 with Y/N</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-1-0-with-Y-N/m-p/611743#M178359</link>
      <description>&lt;P&gt;This will convert all 0/1 to n/y.&amp;nbsp; Many variables. And preserve variable order as specified in VAR statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ind;
   length ind_name ind_adr ind_sal 8.;
   array _ind[*] ind_:;
   do subject=1 to 10;
      do i = 1 to dim(_ind);
         _ind[i] = ranbin(1234,1,.5);
         end;
      output;
      end;
   drop i;
   attrib ind_: label='Label to preserve';
   run;
proc format; value yn 1='Y' 0='N';
proc transpose data=ind out=flip;
   by subject;
   var ind_:;
   format ind_: yn.;
   run;
proc print;
   run;
proc transpose data=yn out=ind2(drop=_name_);
   by subject;
   var yn;
   id _name_;
   idlabel _label_;
   run;
proc print;
   run;
proc contents varnum;
   run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 272px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34768i0F2E53C9C247C313/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 273px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34769i69549B1F744A3AA9/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 21:48:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-1-0-with-Y-N/m-p/611743#M178359</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2019-12-13T21:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: replace 1/0 with Y/N</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-1-0-with-Y-N/m-p/611746#M178361</link>
      <description>&lt;P&gt;Here is the start of a solution. It could be improved by dynamically creating a RENAME = list using SAS DICTIONARY tables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  drop tmp_:;
  array indicators (*) ind_V1 ind_V2;
  array tmp_indicators (*) tmp_ind_V1 tmp_ind_V2;
  set have (rename = (ind_V1 = tmp_ind_V1 ind_V2 = tmp_ind_V2));
  do i = 1 to dim(indicators);
   indicators(i) = put(tmp_indicators(i), yn.);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Dec 2019 21:58:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-1-0-with-Y-N/m-p/611746#M178361</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-12-13T21:58:07Z</dc:date>
    </item>
  </channel>
</rss>

