<?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: how to get even and odd values using array do loop in below example in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-even-and-odd-values-using-array-do-loop-in-below/m-p/903159#M356896</link>
    <description>&lt;P&gt;Do you need something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[EDIT: small I/O update]&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data even_odd;
  array v[20] value1-value20 (1:20);
run;


data _null_;
    set even_odd(obs=1);

    array v value1-value20;
    length odd_list even_list $ 32767;
    do over V;
      if mod(_I_,2)=1 
        then odd_list = catx(" ", odd_list, vname(v));
        else even_list = catx(" ", even_list, vname(v));
    end;

    call execute('data even(keep=' !! strip(even_list) !! ') odd(keep=' !! strip(odd_list) !! '); set even_odd; run;');
    
stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Wed, 15 Nov 2023 10:55:41 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2023-11-15T10:55:41Z</dc:date>
    <item>
      <title>how to get even and odd values using array do loop in below example</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-even-and-odd-values-using-array-do-loop-in-below/m-p/902470#M356655</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data even_odd;
array v[20] value1-value20;
do values= 1 to 20;
v[values]=values;
end;
 drop values;
run;

data even_values;
set even_odd;
array v[20] value1-value20;
do values = 1 to 20;
if mod(values,2)=0  then output;
       
    
end;
drop values;
run;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How to get even and odd values using above array&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Nov 2023 11:30:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-even-and-odd-values-using-array-do-loop-in-below/m-p/902470#M356655</guid>
      <dc:creator>pavank</dc:creator>
      <dc:date>2023-11-10T11:30:47Z</dc:date>
    </item>
    <item>
      <title>Re: how to get even and odd values using array do loop in below example</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-even-and-odd-values-using-array-do-loop-in-below/m-p/902471#M356656</link>
      <description>&lt;P&gt;Is this what you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data even_values;
    set even_odd;
    array v[20] value1-value20;
    do values = 1 to 20;
         if mod(v(values),2)=0 then output;     
    end;
    drop value1-value20;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course, this only works because you have set up the data such that (for example) v(18) is equal to 18, and v(17) is equal to 17, and so on. If you want code for a more general case, where the value of v(18) could be 3, then the above code will not work. So, do you want to handle this more general case? Please state clearly.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Nov 2023 12:04:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-even-and-odd-values-using-array-do-loop-in-below/m-p/902471#M356656</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-11-10T12:04:10Z</dc:date>
    </item>
    <item>
      <title>Re: how to get even and odd values using array do loop in below example</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-even-and-odd-values-using-array-do-loop-in-below/m-p/902472#M356657</link>
      <description>Hi Paige,&lt;BR /&gt;I want Horizontal way  val1-val20</description>
      <pubDate>Fri, 10 Nov 2023 11:39:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-even-and-odd-values-using-array-do-loop-in-below/m-p/902472#M356657</guid>
      <dc:creator>pavank</dc:creator>
      <dc:date>2023-11-10T11:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: how to get even and odd values using array do loop in below example</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-even-and-odd-values-using-array-do-loop-in-below/m-p/902474#M356659</link>
      <description>&lt;P&gt;Run PROC TRANSPOSE on the results of my code.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Nov 2023 11:40:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-even-and-odd-values-using-array-do-loop-in-below/m-p/902474#M356659</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-11-10T11:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: how to get even and odd values using array do loop in below example</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-even-and-odd-values-using-array-do-loop-in-below/m-p/902561#M356690</link>
      <description>&lt;P&gt;I don't understand what an EVEN value of an ARRAY means.&lt;/P&gt;
&lt;P&gt;You can test if particular variables in the array have odd or even values, but a test for the full array makes no sense.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want convert your array back into a series of observations?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps at that point keep only the even (or odd) values?&amp;nbsp; Or split them into two different datasets?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data evens odds;
  set even_odd;
  array v value1-value20;
  do index=1 to dim(v);
     value=v[index];
     if 0=mod(value,2) then output evens;
    else output odds;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or perhaps keep only the values of the odd (or even) variable numbers?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data evens odds;
  set even_odd;
  array v value1-value20;
  do index=1 to dim(v);
     value=v[index];
     if 0=mod(index,2) then output evens;
    else output odds;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do you want to convert the even (or odd) values in the array to missing?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data odds;
  set even_odd;
  array v value1-value20;
  do index=1 to dim(v);
     if 0=mod(v[index],2) then v[index]=.;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Nov 2023 17:09:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-even-and-odd-values-using-array-do-loop-in-below/m-p/902561#M356690</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-11-10T17:09:08Z</dc:date>
    </item>
    <item>
      <title>Re: how to get even and odd values using array do loop in below example</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-even-and-odd-values-using-array-do-loop-in-below/m-p/902564#M356693</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/390518"&gt;@pavank&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems that neither&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;nor I really know what you want as output. Don't make us guess. Show us a screen capture of the desired output; use the "Insert Photos" icon to include your screen capture in your reply; do NOT attach files.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Nov 2023 17:32:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-even-and-odd-values-using-array-do-loop-in-below/m-p/902564#M356693</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-11-10T17:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: how to get even and odd values using array do loop in below example</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-even-and-odd-values-using-array-do-loop-in-below/m-p/902663#M356729</link>
      <description>&lt;P&gt;Here's a third vote for "I haven't a clue what you actually want". &lt;/P&gt;
&lt;P&gt;Show us.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't even mention why you don't like the result of your current code. I suspect something related to having the exact same output 10 times with all the variables and all the values the same.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/390518"&gt;@pavank&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data even_odd;
array v[20] value1-value20;
do values= 1 to 20;
v[values]=values;
end;
 drop values;
run;

data even_values;
set even_odd;
array v[20] value1-value20;
do values = 1 to 20;
if mod(values,2)=0  then output;
       
    
end;
drop values;
run;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How to get even and odd values using above array&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Nov 2023 16:45:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-even-and-odd-values-using-array-do-loop-in-below/m-p/902663#M356729</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-11-11T16:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: how to get even and odd values using array do loop in below example</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-even-and-odd-values-using-array-do-loop-in-below/m-p/902685#M356745</link>
      <description>&lt;P&gt;It's very unclear what you're asking for. Hopefully below code will give you at least some guidance for what you are really trying to achieve.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data even;
  array value_[20] 8;
  do i= 1 to dim(value_);
    value_[i]=i*2;
  end;
  drop i;
run;

proc print data=even;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1699756223388.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/89684iFA59D7C64E717114/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1699756223388.png" alt="Patrick_0-1699756223388.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Nov 2023 02:30:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-even-and-odd-values-using-array-do-loop-in-below/m-p/902685#M356745</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-11-12T02:30:48Z</dc:date>
    </item>
    <item>
      <title>Re: how to get even and odd values using array do loop in below example</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-even-and-odd-values-using-array-do-loop-in-below/m-p/903141#M356887</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;
&lt;P&gt;I want horizantal rows even and odd with mod function required output like below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 432pt;" border="0" width="576" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl64" style="height: 15.0pt; width: 48pt;"&gt;value2&lt;/TD&gt;
&lt;TD width="64" class="xl64" style="border-left: none; width: 48pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="64" class="xl64" style="border-left: none; width: 48pt;"&gt;value4&lt;/TD&gt;
&lt;TD width="64" class="xl64" style="border-left: none; width: 48pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="64" class="xl64" style="border-left: none; width: 48pt;"&gt;value6&lt;/TD&gt;
&lt;TD width="64" class="xl64" style="border-left: none; width: 48pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="64" class="xl64" style="border-left: none; width: 48pt;"&gt;value8&lt;/TD&gt;
&lt;TD width="64" class="xl64" style="border-left: none; width: 48pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="64" class="xl64" style="border-left: none; width: 48pt;"&gt;value10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl64" style="height: 15.0pt; border-top: none;"&gt;2&lt;/TD&gt;
&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;4&lt;/TD&gt;
&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;6&lt;/TD&gt;
&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;8&lt;/TD&gt;
&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Wed, 15 Nov 2023 08:50:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-even-and-odd-values-using-array-do-loop-in-below/m-p/903141#M356887</guid>
      <dc:creator>pavank</dc:creator>
      <dc:date>2023-11-15T08:50:39Z</dc:date>
    </item>
    <item>
      <title>Re: how to get even and odd values using array do loop in below example</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-even-and-odd-values-using-array-do-loop-in-below/m-p/903151#M356893</link>
      <description>&lt;P&gt;So you want some kind of report with some completely empty columns (without header)?&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2023 10:11:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-even-and-odd-values-using-array-do-loop-in-below/m-p/903151#M356893</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-11-15T10:11:24Z</dc:date>
    </item>
    <item>
      <title>Re: how to get even and odd values using array do loop in below example</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-even-and-odd-values-using-array-do-loop-in-below/m-p/903159#M356896</link>
      <description>&lt;P&gt;Do you need something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[EDIT: small I/O update]&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data even_odd;
  array v[20] value1-value20 (1:20);
run;


data _null_;
    set even_odd(obs=1);

    array v value1-value20;
    length odd_list even_list $ 32767;
    do over V;
      if mod(_I_,2)=1 
        then odd_list = catx(" ", odd_list, vname(v));
        else even_list = catx(" ", even_list, vname(v));
    end;

    call execute('data even(keep=' !! strip(even_list) !! ') odd(keep=' !! strip(odd_list) !! '); set even_odd; run;');
    
stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2023 10:55:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-even-and-odd-values-using-array-do-loop-in-below/m-p/903159#M356896</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-11-15T10:55:41Z</dc:date>
    </item>
  </channel>
</rss>

