<?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 character variable to binary value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-variable-to-binary-value/m-p/911848#M359529</link>
    <description>&lt;P&gt;I am skeptical about this re-arrangement of the data. In the real world, medications are going to have names like Hydroxyzine, and then do you really want SAS variables to be named&amp;nbsp;Hydroxyzine and AcetylSalicilic and so on? In addition, I can't see how this proposed re-arrangement of the data is useful for additional analyses.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A much better re-arrangement would be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Patient $ Medication1	$ Medication2 $	Medication3 $;
cards;
ID1	A	B C
ID2	C	E F
ID3	E	G H
;

data want;
    set have;
    medication=medication1;
    output;
    medication=medication2;
    output;
    medication=medication3;
    output;
    drop medication1-medication3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 17 Jan 2024 18:51:42 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2024-01-17T18:51:42Z</dc:date>
    <item>
      <title>How to convert character variable to binary value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-variable-to-binary-value/m-p/911845#M359527</link>
      <description>&lt;P&gt;I have some patients' medication data, need to convert it to binary table. Anyone has the solution?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what I have:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt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t;/TR&gt;&lt;TR&gt;&lt;TD&gt;ID2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ID3&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 17 Jan 2024 18:26:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-variable-to-binary-value/m-p/911845#M359527</guid>
      <dc:creator>JillChen0131</dc:creator>
      <dc:date>2024-01-17T18:26:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert character variable to binary value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-variable-to-binary-value/m-p/911848#M359529</link>
      <description>&lt;P&gt;I am skeptical about this re-arrangement of the data. In the real world, medications are going to have names like Hydroxyzine, and then do you really want SAS variables to be named&amp;nbsp;Hydroxyzine and AcetylSalicilic and so on? In addition, I can't see how this proposed re-arrangement of the data is useful for additional analyses.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A much better re-arrangement would be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Patient $ Medication1	$ Medication2 $	Medication3 $;
cards;
ID1	A	B C
ID2	C	E F
ID3	E	G H
;

data want;
    set have;
    medication=medication1;
    output;
    medication=medication2;
    output;
    medication=medication3;
    output;
    drop medication1-medication3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2024 18:51:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-variable-to-binary-value/m-p/911848#M359529</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-01-17T18:51:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert character variable to binary value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-variable-to-binary-value/m-p/911851#M359530</link>
      <description>&lt;P&gt;First a comment on "binary". That means two values, typically 1 and 0. You only show one value, the 1, which would technically be unary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your given example this creates binary values, 1 where present and 0 where not. Caveats to follow:&lt;/P&gt;
&lt;PRE&gt;data have;
input Patient $	Medication1 $	Medication2 $	Medication3 $;
datalines;
ID1	A	B	C
ID2	C	E	F
ID3	E	G	H
;

data want;
   set have;
   array m (*) medication: ;
   array n (*) A B C D E F G H;
   array v (8) $ 1 _temporary_('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H');
   do i=1 to dim(v);
      n[i] = whichc(v[i],of m(*))&amp;gt;0;
   end;
   drop Medication: i;
run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The WHICHC function searches for matches of the first parameter in the remaining list of values and returns the position number if found or 0 if not found. This match is case sensitive. So with this ALL of your values may need to have the case standardized.&lt;/P&gt;
&lt;P&gt;I have assumed that your actual values are likely to be different than actually the letters A B etc. due to the name for the variables with Medication. I suspect you actually have medication names. If so you need to change the names of the variables in the N array to something acceptable as SAS variable names, no hyphens, spaces or slash characters. The values in the V array would be the standardized spelling of the actual words that appear and the number following the $ needs to be large enough to hold the longest actual text that appears.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Arrays are one way to handle multiple variables in a similar way. Also a group of values may often be addressed with the "of arrayname(*)" syntax in functions that allow lists of values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2024 19:06:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-variable-to-binary-value/m-p/911851#M359530</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-01-17T19:06:54Z</dc:date>
    </item>
  </channel>
</rss>

