<?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 Create a new variable based on certain aspects of an existing character variable... in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Create-a-new-variable-based-on-certain-aspects-of-an-existing/m-p/148248#M39214</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello SAS Community,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am working on analyzing a multiple response survey question.&amp;nbsp; It has seven possible selections and respondents were allowed to choose as many of the selections as applied to them.&amp;nbsp; Unfortunately, this has left me in a bit of an analysis bind.&amp;nbsp; The variable was sent to me as a character variable, and all the possible selections were concatenated into one long string.&amp;nbsp; So the variable values look something like: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 010306&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0204&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01&lt;/P&gt;&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0502&lt;/P&gt;&lt;P&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0205&lt;/P&gt;&lt;P&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01040507&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;As it is, this variable is not providing me with much information.&amp;nbsp; I would like to create a new variable for analysis, where if the original variable contained lets say 01somewhere in its string it would be counted as 1, 02 would be 2, etc.&amp;nbsp; Is there a way to subset observations into a new variable based on the whether it contains a specific character combination?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As always, I greatly appreciate your help&amp;nbsp; and expertise!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 19 Jun 2014 15:13:56 GMT</pubDate>
    <dc:creator>KageKitsune28</dc:creator>
    <dc:date>2014-06-19T15:13:56Z</dc:date>
    <item>
      <title>Create a new variable based on certain aspects of an existing character variable...</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-a-new-variable-based-on-certain-aspects-of-an-existing/m-p/148248#M39214</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello SAS Community,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am working on analyzing a multiple response survey question.&amp;nbsp; It has seven possible selections and respondents were allowed to choose as many of the selections as applied to them.&amp;nbsp; Unfortunately, this has left me in a bit of an analysis bind.&amp;nbsp; The variable was sent to me as a character variable, and all the possible selections were concatenated into one long string.&amp;nbsp; So the variable values look something like: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 010306&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0204&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01&lt;/P&gt;&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0502&lt;/P&gt;&lt;P&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0205&lt;/P&gt;&lt;P&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01040507&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;As it is, this variable is not providing me with much information.&amp;nbsp; I would like to create a new variable for analysis, where if the original variable contained lets say 01somewhere in its string it would be counted as 1, 02 would be 2, etc.&amp;nbsp; Is there a way to subset observations into a new variable based on the whether it contains a specific character combination?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As always, I greatly appreciate your help&amp;nbsp; and expertise!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jun 2014 15:13:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-a-new-variable-based-on-certain-aspects-of-an-existing/m-p/148248#M39214</guid>
      <dc:creator>KageKitsune28</dc:creator>
      <dc:date>2014-06-19T15:13:56Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable based on certain aspects of an existing character variable...</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-a-new-variable-based-on-certain-aspects-of-an-existing/m-p/148249#M39215</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Something like:&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;id=1;result="010306"; output;&lt;BR /&gt;id=2;result="0204"; output;&lt;BR /&gt;id=3;result="01"; output;&lt;BR /&gt;id=4;result="0502"; output;&lt;BR /&gt;id=5;result="0205"; output;&lt;BR /&gt;id=6;result="01040507"; output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want (drop=i);&lt;BR /&gt;&amp;nbsp; set have;&lt;BR /&gt;&amp;nbsp; array result_out{7};&lt;BR /&gt;&amp;nbsp; do i=1 to 7;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if index(result,"0"||strip(put(i,best.)))&amp;gt;0 then result_out{i}=i;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;run;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jun 2014 15:21:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-a-new-variable-based-on-certain-aspects-of-an-existing/m-p/148249#M39215</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-06-19T15:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable based on certain aspects of an existing character variable...</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-a-new-variable-based-on-certain-aspects-of-an-existing/m-p/148250#M39216</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would subtr() out each answer, and out put it to a common variable, which means some kind of transponing the data set.&lt;/P&gt;&lt;P&gt;Then counting can be done with whatever tool/procedure you like.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; no = length(response);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i =1 to no by 2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; single_response = substr(response,i,2);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; keep response_id single_response;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select single_response, count(*) as no_resp&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from want&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by single_response&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jun 2014 15:34:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-a-new-variable-based-on-certain-aspects-of-an-existing/m-p/148250#M39216</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2014-06-19T15:34:36Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable based on certain aspects of an existing character variable...</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-a-new-variable-based-on-certain-aspects-of-an-existing/m-p/148251#M39217</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;LOL, just noticed.&amp;nbsp; &lt;A __default_attr="814511" __jive_macro_name="user" class="jive_macro jive_macro_user" href="https://communities.sas.com/"&gt;&lt;/A&gt;, you put yourself in a typical length trap. I learned it by reading one of books by &lt;A __default_attr="5253" __jive_macro_name="user" class="jive_macro jive_macro_user" href="https://communities.sas.com/"&gt;&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jun 2014 15:45:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-a-new-variable-based-on-certain-aspects-of-an-existing/m-p/148251#M39217</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2014-06-19T15:45:00Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable based on certain aspects of an existing character variable...</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-a-new-variable-based-on-certain-aspects-of-an-existing/m-p/148252#M39218</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you a paying a company to administer your survey then I would address this issue with them to provide the data in another format. Many survey software options allow taking a multiple response question and exporting them as Q1_1 through Q1_n where n represents the number of responses as 0/1 coded dichotomous variables to indicate that choice was selected.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If order of response is not important to you, this may be what you are looking for:&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; q1_1 = (index(result,'01') &amp;gt;0);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; q1_2 = (index(result,'02') &amp;gt;0); &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; q1_3 = (index(result,'03') &amp;gt;0); &lt;/P&gt;&lt;P&gt;/* continue obvious pattern*/&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;If you have more than 10 response categories and get strings like 02031011 you need to add in some code to use boundaries of the 2 characters like&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Q1_2 = (mod(index(result,'02'),2)=1);&lt;/P&gt;&lt;P&gt;This type of coding will assign 0 to those questions without responses which I find useful because a mean of the question will give a percent of respondents picking that choice and a sum the number that did plus you can get confidence intervals on the proportions.&lt;/P&gt;&lt;P&gt;If there is a skip pattern involved then only execute the code where the skip says the respondent should have answered the quesion.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jun 2014 16:13:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-a-new-variable-based-on-certain-aspects-of-an-existing/m-p/148252#M39218</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-06-19T16:13:36Z</dc:date>
    </item>
  </channel>
</rss>

