<?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: Re-coding a variable using arrays in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528170#M144111</link>
    <description>&lt;P&gt;A quick fix that takes care of invalid data entries could be like below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notice how I purposely added an invalid response number of 15 in the third observation, which is now handled. However, I would probably clean the data properly at an earlier state.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Q12 $20.;
datalines;
1 1,2,3,4,5
2 4,11,13
3 6,7,8,9,10,11,15
;

data want(drop=i j idx);
   set have(rename=(Q12=_Q12));
   array Q{14} Q1-Q14 (14*0);

   do i=1 to countw(_Q12, ',');
      idx=input(scan(_Q12, i, ','), 8.);
      if idx in (1:14) then Q[idx]=1;
   end;

   output;

   do j=1 to dim(Q);
      Q[j]=0;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 17 Jan 2019 21:23:43 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2019-01-17T21:23:43Z</dc:date>
    <item>
      <title>Re-coding a variable using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528130#M144095</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm in the process of cleaning a dataset (from a survey) using SAS 9.4 and I'm trying to figure out a more streamlined process for cleaning one of the variables (called Q12). For this question, people were allowed to select more than one response, and all of their choices were combined into one variable (Q12), separated by commas. There were 14 choices that they could select. An example of what the data looks like is below:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Q12&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1,2,3,4,5&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4,11,13&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6,7,8,9,10,11&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to re-code Q12 into 14 variables corresponding to each of the question choices. For example, I would create a new variable called Q12_1 for all of the people who selected choice 1 and it would be coded 0 or 1 (0= did not select, 1 = did select), and so on and so forth. I was going to use the INDEX function to pull the choice # (1-14) in Q12, and I could just do this 14 times, but I wanted a more efficient way of doing it. Here's the code I could use:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA TEST;&lt;BR /&gt;SET CLEAN_DATASET;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if index(Q12, "1") then Q12_1 = 1;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;else if Q12 = ' ' then Q12_1 = .;&lt;BR /&gt;else Q12_1 = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I could repeat this IF statement 14 times, swapping out the "1" for every choice #, but I want to learn how to do this using some kind of loop like an array to save myself time.&amp;nbsp;However, I've been running into trouble because I can't figure out how to create a loop of the numbers 1-14 in the code below:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA TEST;&lt;BR /&gt;SET CLEAN_DATASET;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;array X [14] Q12_1 Q12_2 Q12_3&amp;nbsp;Q12_4 Q12_5 Q12_6 Q12_7 Q12_8 Q12_9 Q12_10 Q12_11 Q12_12 Q12_13 Q12_14;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;do i = 1 to 14;&lt;/P&gt;&lt;P&gt;if index(Q12, "i") then X[i] = 1;&lt;BR /&gt;else if Q12 = ' ' then X[i] = .;&lt;BR /&gt;else X[i] = 0;&lt;/P&gt;&lt;P&gt;end;&lt;BR /&gt;Drop i;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I seem to be running into trouble with the INDEX function. When I ran this, my newly created variables only contained 0's and blanks, instead of 1's as well. I also tried adding another DO loop and a temporary array but that didn't work either. Any suggestions??&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 19:35:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528130#M144095</guid>
      <dc:creator>685932</dc:creator>
      <dc:date>2019-01-17T19:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: Re-coding a variable using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528138#M144097</link>
      <description>&lt;P&gt;Welcome to the SAS communities &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is probably a simpler way, but here is my approach&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Q12 $20.;
datalines;
1 1,2,3,4,5
2 4,11,13
3 6,7,8,9,10,11
;

data want(drop=i j idx);
   set have(rename=(Q12=_Q12));
   array Q{14} Q1-Q14 (14*0);

   do i=1 to countw(_Q12, ',');
      idx=input(scan(_Q12, i, ','), 8.);
      Q[idx]=1;
   end;

   output;

   do j=1 to dim(Q);
      Q[j]=0;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Jan 2019 20:03:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528138#M144097</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-17T20:03:05Z</dc:date>
    </item>
    <item>
      <title>Re: Re-coding a variable using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528147#M144103</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input ID Q12 $20.;
datalines;
1 1,2,3,4,5
2 4,11,13
3 6,7,8,9,10,11
4 .
5 1,9
6 .
;
data want;
set have;
array t Q12_1-Q12_14 (14*0);
retain k;
if _n_ = 1 then k = peekclong(addrlong (t[1]), 112);
else  call pokelong(k, addrlong (t[1]), 112) ; 
do i=1 to countw(q12);
j=scan(q12,i);
t(input(j,8.))=1;
end;
if 1 not in t then call missing(of t(*));
drop k j i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Jan 2019 23:13:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528147#M144103</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-17T23:13:09Z</dc:date>
    </item>
    <item>
      <title>Re: Re-coding a variable using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528164#M144108</link>
      <description>&lt;P&gt;Thank you very much for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried your code, but I got this error message:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;25 GOPTIONS ACCESSIBLE;&lt;BR /&gt;26 Data TEST(drop = i j idx);&lt;BR /&gt;27 Set CLEAN_DATASET(rename = (Q12 = _Q12));&lt;BR /&gt;28&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;29 Array Q[14] Q12_1-Q12_14 (14*0);&lt;BR /&gt;30&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;31 do i = 1 to countw(_Q12, ',');&lt;BR /&gt;32 idx = input(scan(_Q12, i, ','), 8.);&lt;BR /&gt;33 Q[idx] = 1;&lt;BR /&gt;34 end;&lt;BR /&gt;35&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;36 output;&lt;BR /&gt;37&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;38 do j = 1 to dim(Q);&lt;BR /&gt;39 Q[j] = 0;&lt;BR /&gt;40&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;41 end;&lt;BR /&gt;42&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;43 run;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR: Array subscript out of range at line 33 column 1.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 21:06:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528164#M144108</guid>
      <dc:creator>685932</dc:creator>
      <dc:date>2019-01-17T21:06:00Z</dc:date>
    </item>
    <item>
      <title>Re: Re-coding a variable using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528166#M144109</link>
      <description>&lt;P&gt;This would happen if your test answers contain values other than 1,2,3,4,5,6,7,8,9,10,11,12,13 and 14 ..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which is not the case in your posted example data. But may be the case in your actual data. Am I correct?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 21:13:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528166#M144109</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-17T21:13:40Z</dc:date>
    </item>
    <item>
      <title>Re: Re-coding a variable using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528167#M144110</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $ Q12 $15.;
cards;
1 1,2,3,4,5
2 4,11,13
3 6,7,8,9,10,11
4 .
5 1,19
6 .
;
run;

data want;
	set have;
	len=length(Q12);
	array q[*] Q1-Q6;

	do i=1 to len;
		call scan(Q12,i,pos,ln,',');

		if not pos then
			leave;

		if input(substrn(q12,pos,ln),8.) then
			q[i]=1;
	end;

	do j=1 to dim(q);
		if missing(q[j]) then
			q[j]=0;
	end;

	drop pos ln i len j;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Jan 2019 22:07:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528167#M144110</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2019-01-17T22:07:34Z</dc:date>
    </item>
    <item>
      <title>Re: Re-coding a variable using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528170#M144111</link>
      <description>&lt;P&gt;A quick fix that takes care of invalid data entries could be like below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notice how I purposely added an invalid response number of 15 in the third observation, which is now handled. However, I would probably clean the data properly at an earlier state.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Q12 $20.;
datalines;
1 1,2,3,4,5
2 4,11,13
3 6,7,8,9,10,11,15
;

data want(drop=i j idx);
   set have(rename=(Q12=_Q12));
   array Q{14} Q1-Q14 (14*0);

   do i=1 to countw(_Q12, ',');
      idx=input(scan(_Q12, i, ','), 8.);
      if idx in (1:14) then Q[idx]=1;
   end;

   output;

   do j=1 to dim(Q);
      Q[j]=0;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 21:23:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528170#M144111</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-17T21:23:43Z</dc:date>
    </item>
    <item>
      <title>Re: Re-coding a variable using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528172#M144112</link>
      <description>&lt;P&gt;Thank you, I will try this. The actual data contains missing values, which I am assuming is why there was an error? I want to keep the missing values as missing, and not code them as 0.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 21:23:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528172#M144112</guid>
      <dc:creator>685932</dc:creator>
      <dc:date>2019-01-17T21:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: Re-coding a variable using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528175#M144113</link>
      <description>&lt;P&gt;What does a missing value look like in this context? Two commas in a row? Please edit the data step that I created of your posted example data to shows us.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, how do you want to 'keep' the missing values here?&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 have;
input ID Q12 $20.;
datalines;
1 1,2,3,4,5
2 4,11,13
3 6,7,8,9,10,11
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 21:31:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528175#M144113</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-17T21:31:41Z</dc:date>
    </item>
    <item>
      <title>Re: Re-coding a variable using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528180#M144114</link>
      <description>&lt;P&gt;Sorry, I should have been more clear. A missing value in my dataset is someone who didn't answer the question at all. I want to be able to distinguish between those who didn't answer the question, and people who did answer the question but may not have selected a certain choice (I would code the choices they didn't select as 0).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's an example:&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;ID&lt;/SPAN&gt; Q12 &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;20&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token keyword"&gt;datalines&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token data string"&gt;1 1,2,3,4,5
2 4,11,13
3 6,7,8,9,10,11&lt;BR /&gt;4 .&lt;BR /&gt;5 1,9&lt;BR /&gt;6 .&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;ID 4 and 6 is what a missing value would look like. If a person answered the question but didn't select a certain choice, the missing choices aren't listed (see ID 1,2,3, and 5).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to code things like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For ID 5, for example, I would code Q12_1 and Q12_9 =1 and all the other variables would be coded as 0 (since this person answered the question). But for ID 6, I would code all the variables = missing.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 22:00:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528180#M144114</guid>
      <dc:creator>685932</dc:creator>
      <dc:date>2019-01-17T22:00:32Z</dc:date>
    </item>
    <item>
      <title>Re: Re-coding a variable using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528181#M144115</link>
      <description>&lt;P&gt;Well that got messed up...sorry let me try that again&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input ID Q12 $20.;&lt;BR /&gt;datalines;&lt;BR /&gt;1 1,2,3,4,5&lt;BR /&gt;2 4,11,13&lt;BR /&gt;3 6,7,8,9,10,11&lt;/P&gt;&lt;P&gt;4 .&lt;/P&gt;&lt;P&gt;5 1,9&lt;/P&gt;&lt;P&gt;6 .&lt;BR /&gt;;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 22:02:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528181#M144115</guid>
      <dc:creator>685932</dc:creator>
      <dc:date>2019-01-17T22:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: Re-coding a variable using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528183#M144116</link>
      <description>&lt;P&gt;I don't see an ID 4, 5 or 6 in your data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&amp;nbsp;I got it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 22:05:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528183#M144116</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-17T22:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: Re-coding a variable using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528184#M144117</link>
      <description>&lt;P&gt;Ok. This gives you what you want &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Q12 $20.;
datalines;
1 1,2,3,4,5
2 4,11,13
3 6,7,8,9,10,11
4 .
5 1,9
6 .
;

data want(drop=i j idx);
   set have(rename=(Q12=_Q12));
   array Q{14} Q1-Q14 (14*0);

   put _Q12;

   do i=1 to countw(_Q12, ',');
      idx=input(scan(_Q12, i, ','), 8.);
      if idx in (1:14) then Q[idx]=1;
   end;

   if sum(of Q[*]) eq 0 then call missing(of Q[*]);

   output;

   do j=1 to dim(Q);
      Q[j]=0;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Jan 2019 22:13:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528184#M144117</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-17T22:13:00Z</dc:date>
    </item>
    <item>
      <title>Re: Re-coding a variable using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528309#M144174</link>
      <description>&lt;P&gt;This worked! Thank you!!&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jan 2019 14:30:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528309#M144174</guid>
      <dc:creator>685932</dc:creator>
      <dc:date>2019-01-18T14:30:37Z</dc:date>
    </item>
    <item>
      <title>Re: Re-coding a variable using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528310#M144175</link>
      <description>&lt;P&gt;This also worked perfectly. Thank you for your help!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jan 2019 14:31:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528310#M144175</guid>
      <dc:creator>685932</dc:creator>
      <dc:date>2019-01-18T14:31:52Z</dc:date>
    </item>
    <item>
      <title>Re: Re-coding a variable using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528314#M144176</link>
      <description>&lt;P&gt;Anytime, glad to help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jan 2019 14:37:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-coding-a-variable-using-arrays/m-p/528314#M144176</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-18T14:37:21Z</dc:date>
    </item>
  </channel>
</rss>

