<?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: CREATING A NEW VARIABLE FROM A &amp;quot;CHECK ALL THAT APPLY&amp;quot; VARIABLE in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/CREATING-A-NEW-VARIABLE-FROM-A-quot-CHECK-ALL-THAT-APPLY-quot/m-p/484909#M125919</link>
    <description>&lt;P&gt;You should use the /debug on your data statement.&lt;/P&gt;&lt;P&gt;See what is happening yourself.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data fun / debug;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* lots of stuff you want to check */&lt;/P&gt;&lt;P&gt;run:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Aug 2018 20:42:52 GMT</pubDate>
    <dc:creator>VDD</dc:creator>
    <dc:date>2018-08-07T20:42:52Z</dc:date>
    <item>
      <title>CREATING A NEW VARIABLE FROM A "CHECK ALL THAT APPLY" VARIABLE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CREATING-A-NEW-VARIABLE-FROM-A-quot-CHECK-ALL-THAT-APPLY-quot/m-p/484888#M125912</link>
      <description>&lt;P&gt;I am analyzing data from a survey with questions whose answers are in the form of checkboxes (i.e. "Check all that apply"). In the raw data, each checkbox (i.e. Response) is its own variable (See below: addiction___1 is the first checkbox, addiction___2 is the second checkbox, etc.). I would like to create a new variable for each question and have each checkbox / response&amp;nbsp;be its own category / level in that variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code below works fine when I am coding one question at a time. Is there a way to automate / condense the syntax so I don't have to write this syntax for each question over and over again?!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	IF addiction___1 THEN DO;
	addiction = 1;
	
	END;
	
	IF addiction___2 THEN DO;
	addiction = 2;
	
	END;
	
	IF addiction___3 THEN DO;
	addiction = 3;
	
	END;
	
	IF addiction___4 THEN DO;
	addiction = 4;
	
	END;
	
	IF addiction___5 THEN DO;
	addiction = 5;
	
	END;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Aug 2018 20:12:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CREATING-A-NEW-VARIABLE-FROM-A-quot-CHECK-ALL-THAT-APPLY-quot/m-p/484888#M125912</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2018-08-07T20:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: CREATING A NEW VARIABLE FROM A "CHECK ALL THAT APPLY" VARIABLE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CREATING-A-NEW-VARIABLE-FROM-A-quot-CHECK-ALL-THAT-APPLY-quot/m-p/484900#M125914</link>
      <description>&lt;P&gt;I'm not sure that this code is really working fine.&amp;nbsp; When both 1 and 2 are checked, your new variable ADDICTION will be 2 and won't capture the fact that 1 was also checked.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 20:27:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CREATING-A-NEW-VARIABLE-FROM-A-quot-CHECK-ALL-THAT-APPLY-quot/m-p/484900#M125914</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-08-07T20:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: CREATING A NEW VARIABLE FROM A "CHECK ALL THAT APPLY" VARIABLE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CREATING-A-NEW-VARIABLE-FROM-A-quot-CHECK-ALL-THAT-APPLY-quot/m-p/484909#M125919</link>
      <description>&lt;P&gt;You should use the /debug on your data statement.&lt;/P&gt;&lt;P&gt;See what is happening yourself.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data fun / debug;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* lots of stuff you want to check */&lt;/P&gt;&lt;P&gt;run:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 20:42:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CREATING-A-NEW-VARIABLE-FROM-A-quot-CHECK-ALL-THAT-APPLY-quot/m-p/484909#M125919</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-08-07T20:42:52Z</dc:date>
    </item>
    <item>
      <title>Re: CREATING A NEW VARIABLE FROM A "CHECK ALL THAT APPLY" VARIABLE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CREATING-A-NEW-VARIABLE-FROM-A-quot-CHECK-ALL-THAT-APPLY-quot/m-p/484921#M125924</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/36911"&gt;@_maldini_&lt;/a&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You're saying "I would like to create a &lt;EM&gt;new variable&lt;/EM&gt; for each question", yet it's not what your code is doing. Rather, it overwrites the value of the ADDICTION variable with a new value X every time the next addiction__X evaluates true. If this is what you really want, you can shorten your code by using:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array add addiction__1-addiction__5 ;

do over add ;
  if add then addiction = _i_ ;
end ;  &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;This way, if none of the boxes is checked, the variable ADDICTION will remain missing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, if instead you want, as you say, to create a new &lt;EM&gt;variable&lt;/EM&gt; for each box and populate variable #1 with 1 is addiction__1 is true, variable #2 - with 2 if&amp;nbsp; addiction__2 is true, and so forth, you'll have to do it differently; for example:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array add addiction__1-addiction__5 ;
array new newvar_1-newvar_5 ;

do over add ;
  if add then new = _i_ ;
end ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This way, if you had the addiction__1-addiction__5 variables valued, for example, as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(unchecked, checked, unchecked, unchecked, checked)&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you'd get newvar_1-newvar_5 populated as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(. 2 . . 5)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But the approach depends on what you really want to get. Unfortunately, you're a bit vague on that head, and discerning your intent from your sample code is uncertain.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Paul D.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 21:47:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CREATING-A-NEW-VARIABLE-FROM-A-quot-CHECK-ALL-THAT-APPLY-quot/m-p/484921#M125924</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2018-08-07T21:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: CREATING A NEW VARIABLE FROM A "CHECK ALL THAT APPLY" VARIABLE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CREATING-A-NEW-VARIABLE-FROM-A-quot-CHECK-ALL-THAT-APPLY-quot/m-p/485182#M126025</link>
      <description>&lt;P&gt;You may want to visit this thread: &lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/consolidating-columns/m-p/484770#M125874" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/consolidating-columns/m-p/484770#M125874&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which has a better description of starting data and I believe at heart is similar to your problem with possibly yours not having an issue with identical responses appearing in multiple variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or perhaps you can provide a more explicit&amp;nbsp;example of existing data set and what you want.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Aug 2018 15:08:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CREATING-A-NEW-VARIABLE-FROM-A-quot-CHECK-ALL-THAT-APPLY-quot/m-p/485182#M126025</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-08T15:08:52Z</dc:date>
    </item>
  </channel>
</rss>

