<?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 Creating dummy variables from variables with multiple values separated by commas in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Creating-dummy-variables-from-variables-with-multiple-values/m-p/544605#M7890</link>
    <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having issues creating dummy variables (CC_Inf1) from a variable (CC_inforcvd2) with multiple values separated by commas. This variable comes from a survey question that asked participants to select all choices that applied to them. There were 13 choices.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code I am using is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data PrePostZ;&lt;BR /&gt;if find(CC_inforcvd2, '1 ','1,') then CC_Inf1=1;&lt;BR /&gt;else CC_Inf1=0;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get results that are close but not exact to the actual count. For example there are 111 people who chose 1 in any sort of combination with other choices, But with this code, only 86 are counted. Please help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Andrea&lt;/P&gt;</description>
    <pubDate>Wed, 20 Mar 2019 15:23:58 GMT</pubDate>
    <dc:creator>aespinarey</dc:creator>
    <dc:date>2019-03-20T15:23:58Z</dc:date>
    <item>
      <title>Creating dummy variables from variables with multiple values separated by commas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-dummy-variables-from-variables-with-multiple-values/m-p/544605#M7890</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having issues creating dummy variables (CC_Inf1) from a variable (CC_inforcvd2) with multiple values separated by commas. This variable comes from a survey question that asked participants to select all choices that applied to them. There were 13 choices.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code I am using is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data PrePostZ;&lt;BR /&gt;if find(CC_inforcvd2, '1 ','1,') then CC_Inf1=1;&lt;BR /&gt;else CC_Inf1=0;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get results that are close but not exact to the actual count. For example there are 111 people who chose 1 in any sort of combination with other choices, But with this code, only 86 are counted. Please help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Andrea&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 15:23:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-dummy-variables-from-variables-with-multiple-values/m-p/544605#M7890</guid>
      <dc:creator>aespinarey</dc:creator>
      <dc:date>2019-03-20T15:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables from variables with multiple values separated by commas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-dummy-variables-from-variables-with-multiple-values/m-p/544608#M7891</link>
      <description>&lt;P&gt;Show us a representative portion of the data. Show us the desired output.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 15:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-dummy-variables-from-variables-with-multiple-values/m-p/544608#M7891</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-03-20T15:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables from variables with multiple values separated by commas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-dummy-variables-from-variables-with-multiple-values/m-p/544610#M7892</link>
      <description>&lt;P&gt;See if this logic is helpful to you. Just took the three first rows of your data..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data exampledata;
CC_inforcvd2="2,3,5,7,10,11";output;
CC_inforcvd2="1,2,3,5";output;
CC_inforcvd2="12";output;
run;

data want;
   set exampledata;
   array CC_Inf{12};
   do i = 1 to dim(CC_Inf);
      CC_Inf[i]=0;
   end;

   do i = 1 to countw(CC_inforcvd2, ',');
      idx=input(scan(CC_inforcvd2, i, ','), 8.);
      CC_Inf[idx]=1;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From the look of you PDF file it seems like you write a lot of code that is not necessary. With the above logic you only have to read the data once &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 15:44:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-dummy-variables-from-variables-with-multiple-values/m-p/544610#M7892</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-03-20T15:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables from variables with multiple values separated by commas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-dummy-variables-from-variables-with-multiple-values/m-p/544617#M7893</link>
      <description>&lt;P&gt;Stealing from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;for example data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data exampledata;
CC_inforcvd2="2,3,5,7,10,11";output;
CC_inforcvd2="1,2,3,5";output;
CC_inforcvd2="12";output;
run;

data want;
   set exampledata;
   array CC_Inf{12};
   do i = 1 to dim(CC_Inf);
      CC_Inf[i]= findw(CC_inforcvd2,strip(put(i,best2.)))&amp;gt;0;
   end;
run;&lt;/PRE&gt;
&lt;P&gt;Uses findw default behavior of treating a comma as delimiter. Strip is needed to use "2" instead of " 2" as the search value.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 15:49:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-dummy-variables-from-variables-with-multiple-values/m-p/544617#M7893</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-20T15:49:28Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables from variables with multiple values separated by commas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-dummy-variables-from-variables-with-multiple-values/m-p/544619#M7894</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;stealing my example data &lt;EM&gt;and&lt;/EM&gt; writing more efficient code.. Shame on you &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 15:51:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-dummy-variables-from-variables-with-multiple-values/m-p/544619#M7894</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-03-20T15:51:31Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables from variables with multiple values separated by commas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-dummy-variables-from-variables-with-multiple-values/m-p/544621#M7895</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;stealing my example data &lt;EM&gt;and&lt;/EM&gt; writing more efficient code.. Shame on you &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I have had to use this approach to cleaning data for years as I deal with a variety of data sources that give me what I consider pseudo-garbage values like that.&lt;/P&gt;
&lt;P&gt;There is one other bit of information this type of format contains that may be of interest if the Order of the output variables might indicate importance. In which case the Findw word position can be used to set a second arrays value of order for the indicator.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 15:57:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-dummy-variables-from-variables-with-multiple-values/m-p/544621#M7895</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-20T15:57:21Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables from variables with multiple values separated by commas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-dummy-variables-from-variables-with-multiple-values/m-p/547656#M8409</link>
      <description>&lt;P&gt;Thank you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; I greatly appreciate it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2019 16:44:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-dummy-variables-from-variables-with-multiple-values/m-p/547656#M8409</guid>
      <dc:creator>aespinarey</dc:creator>
      <dc:date>2019-04-01T16:44:04Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables from variables with multiple values separated by commas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-dummy-variables-from-variables-with-multiple-values/m-p/547657#M8410</link>
      <description>&lt;P&gt;Thank you so much, it worked beautifully. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2019 16:44:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-dummy-variables-from-variables-with-multiple-values/m-p/547657#M8410</guid>
      <dc:creator>aespinarey</dc:creator>
      <dc:date>2019-04-01T16:44:34Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables from variables with multiple values separated by commas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-dummy-variables-from-variables-with-multiple-values/m-p/548114#M8482</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a question&amp;nbsp;&lt;/P&gt;&lt;P&gt;the multiple values of mine as follows( obs1=1,2,3. obs2=3,2,4,5. obs3=4,1,2,3. so on)&lt;/P&gt;&lt;P&gt;so should i specify each sot of the multiple values individually in this code ?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data exampledata;
CC_inforcvd2="2,3,5,7,10,11";output;
CC_inforcvd2="1,2,3,5";output;
CC_inforcvd2="12";output;
run;

data want;
   set exampledata;
   array CC_Inf{12};
   do i = 1 to dim(CC_Inf);
      CC_Inf[i]= findw(CC_inforcvd2,strip(put(i,best2.)))&amp;gt;0;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp; that what i understood.&lt;/P&gt;&lt;P&gt;Also could i use this proc to categorize the multiple values based on first value in the multiple values? for instance: either obs contains 1 as first value change into zero.&lt;/P&gt;&lt;P&gt;thanks in advance&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2019 07:00:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-dummy-variables-from-variables-with-multiple-values/m-p/548114#M8482</guid>
      <dc:creator>Radwan</dc:creator>
      <dc:date>2019-04-03T07:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables from variables with multiple values separated by commas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-dummy-variables-from-variables-with-multiple-values/m-p/548252#M8497</link>
      <description>No, they added that as an example of a dataset. You only need the code below that to analyze your dataset&lt;BR /&gt;</description>
      <pubDate>Wed, 03 Apr 2019 15:35:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-dummy-variables-from-variables-with-multiple-values/m-p/548252#M8497</guid>
      <dc:creator>aespinarey</dc:creator>
      <dc:date>2019-04-03T15:35:18Z</dc:date>
    </item>
  </channel>
</rss>

