<?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: Reversing with array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reversing-with-array/m-p/258381#M49749</link>
    <description>&lt;P&gt;You didn't declare an array, so you could start with that &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;You can also use the VNAME function to get the name of the variable and then figure it if it's even or not to apply the transformation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Untested and sketched out below. You may want to verify the results from the numeric conversion and mod function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, you have 29 included in there, when it's not even.&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 want;
set have;

array t1(30) t1sdq1-t1sd130;

do i=1 to dim(t1);
var_name = vname(t1(i));
var_name_number=input(substr(var_name, 6), 8.); 
if mod(var_name_number, 2) = 0 then do;
 t1(i)=9-t1(i);
end;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;An alternative option is to only list the even variables in your array statement, but that's a manual process. Then you don't need the if condition or the vname function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

array t1(15) t1sdq2 t1sdq4 ... t1sdq30; *need to explicitly list them all out;

do i=1 to dim(t1);
   t1(i)=9-t1(i);
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 23 Mar 2016 00:14:01 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-03-23T00:14:01Z</dc:date>
    <item>
      <title>Reversing with array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reversing-with-array/m-p/258378#M49748</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;I need to reverse every even number item in a questionnaire. How could I figure this out with an array statement?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let's assume there are total 30 items but just even numbered items need to be reversed.&lt;/P&gt;&lt;P&gt;DATA sdqreversed;&lt;BR /&gt;set sdq;&lt;BR /&gt;T1SDQ2=9-T1SDQ2;&lt;BR /&gt;T1SDQ4=9-T1SDQ4;&lt;BR /&gt;T1SDQ6=9-T1SDQ6;&lt;BR /&gt;T1SDQ8=9-T1SDQ8;&lt;BR /&gt;T1SDQ10=9-T1SDQ10;&lt;BR /&gt;T1SDQ12=9-T1SDQ12;&lt;BR /&gt;T1SDQ14=9-T1SDQ14;&lt;BR /&gt;T1SDQ16=9-T1SDQ16;&lt;BR /&gt;T1SDQ18=9-T1SDQ18;&lt;BR /&gt;T1SDQ20=9-T1SDQ20;&lt;BR /&gt;T1SDQ22=9-T1SDQ22;&lt;BR /&gt;T1SDQ24=9-T1SDQ24;&lt;BR /&gt;T1SDQ26=9-T1SDQ26;&lt;BR /&gt;T1SDQ28=9-T1SDQ28;&lt;BR /&gt;T1SDQ29=9-T1SDQ29;&lt;BR /&gt;T1SDQ30=9-T1SDQ30;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 23:40:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reversing-with-array/m-p/258378#M49748</guid>
      <dc:creator>mike44</dc:creator>
      <dc:date>2016-03-22T23:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: Reversing with array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reversing-with-array/m-p/258381#M49749</link>
      <description>&lt;P&gt;You didn't declare an array, so you could start with that &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;You can also use the VNAME function to get the name of the variable and then figure it if it's even or not to apply the transformation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Untested and sketched out below. You may want to verify the results from the numeric conversion and mod function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, you have 29 included in there, when it's not even.&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 want;
set have;

array t1(30) t1sdq1-t1sd130;

do i=1 to dim(t1);
var_name = vname(t1(i));
var_name_number=input(substr(var_name, 6), 8.); 
if mod(var_name_number, 2) = 0 then do;
 t1(i)=9-t1(i);
end;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;An alternative option is to only list the even variables in your array statement, but that's a manual process. Then you don't need the if condition or the vname function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

array t1(15) t1sdq2 t1sdq4 ... t1sdq30; *need to explicitly list them all out;

do i=1 to dim(t1);
   t1(i)=9-t1(i);
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Mar 2016 00:14:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reversing-with-array/m-p/258381#M49749</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-23T00:14:01Z</dc:date>
    </item>
    <item>
      <title>Re: Reversing with array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reversing-with-array/m-p/258396#M49753</link>
      <description>&lt;P&gt;Use an array and a loop with an increment of 2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sdqreversed;
set sdq;
array T T1SDQ1-T1SDQ30;
do i = 2 to dim(T) by 2;
	T{i} = 9 - T{i};
	end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Mar 2016 02:05:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reversing-with-array/m-p/258396#M49753</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-03-23T02:05:19Z</dc:date>
    </item>
  </channel>
</rss>

