<?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: Selecting accounts to reverse within an Array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Selecting-accounts-to-reverse-within-an-Array/m-p/338758#M77209</link>
    <description>&lt;P&gt;I had almost the same solution as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;. I post it anyway.&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 a;
	set ORIGINAL;
	keep OBS TYPE VAL;
	array char (*) _CHARACTER_;
	array num (*) _NUMERIC_;
	do i=1 to dim(char);
		OBS=_N_;
		TYPE=char(i);
		VAL=num(i);
		output;
	end;
run;

proc sort data=a;
	by OBS TYPE DESCENDING VAL;
run;

data want;
    set a;
	format TYPE_1-TYPE_6 $1.;
	retain TYPE_1-TYPE_6 NUM_1-NUM_6;
	by OBS;
	array TYPES (*) TYPE_1-TYPE_6;
	array NUMS (*) NUM_1-NUM_6;
	do i=1 to dim(TYPES);
		if mod(_N_,6)=mod(i,6) then do;
			TYPES(i)=TYPE;
			NUMS(i)=VAL;
		end;
	end;

	if last.OBS;
	drop TYPE VAL OBS i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Mar 2017 11:19:14 GMT</pubDate>
    <dc:creator>gamotte</dc:creator>
    <dc:date>2017-03-07T11:19:14Z</dc:date>
    <item>
      <title>Selecting accounts to reverse within an Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-accounts-to-reverse-within-an-Array/m-p/338741#M77200</link>
      <description>&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;Hello, I currently have the data set below and what I am trying to do is reverse the order of the numeric type from lowest to highest to highest to lowest whilst keeping the type in the same order.&lt;BR /&gt;&lt;BR /&gt;E.g. it has to stay A - B - C but the number order switches from 1 - 2 - 3 to 3 - 2 - 1.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ORIGINAL; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; TYPE_1 $ TYPE_2 $ TYPE_3 $ TYPE_4 $ TYPE_5 $ TYPE_6 $ NUM_1 NUM_2 NUM_3 NUM_4 NUM_5 NUM_6; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;A A A B B C 6 8 12 7 8 9&lt;/P&gt;&lt;P&gt;A A B B C C 2 10 1 11 7 10&lt;/P&gt;&lt;P&gt;A B B B B C 7 1 8 9 10 6&lt;/P&gt;&lt;P&gt;A A B C C C 1 3 4 1 2 3&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;I have this code below which will switch it all but the issue with this is that it is also swicthing the char also where I do not need this to happen.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; REVERSE; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;SET&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ORIGINAL;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;ARRAY&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; CHAR [*] TYPE_1 TYPE_2 TYPE_3 TYPE_4 TYPE_5;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;ARRAY&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; NEW_CHAR [*] TYPE_5 TYPE_4 TYPE_3 TYPE_2 TYPE_1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;ARRAY&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; NUM [*] NUM_1 - NUM_5;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;ARRAY&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; NEW_NUM [*] NUM_5 - NUM_1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;CALL&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; SORTC(OF NEW_CHAR[*]);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;CALL&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; SORTN(OF NEW_NUM[*]);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Does anybody know of any code which would allow me to swicth the numeric values around whilst keeping them in the correct character order?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Thank you,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 10:43:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-accounts-to-reverse-within-an-Array/m-p/338741#M77200</guid>
      <dc:creator>Mick_bill</dc:creator>
      <dc:date>2017-03-07T10:43:19Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting accounts to reverse within an Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-accounts-to-reverse-within-an-Array/m-p/338744#M77201</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA REVERSE; SET ORIGINAL;
ARRAY NUM [*] NUM_1 - NUM_5;
ARRAY NEW_NUM [*] NUM_5 - NUM_1;
CALL SORTN(OF NEW_NUM[*]);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;TRY THE ABOVE and see whether it works for you.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 10:32:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-accounts-to-reverse-within-an-Array/m-p/338744#M77201</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2017-03-07T10:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting accounts to reverse within an Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-accounts-to-reverse-within-an-Array/m-p/338750#M77206</link>
      <description>&lt;P&gt;hello,&lt;BR /&gt;&lt;BR /&gt;Thank you for this. The only issue is I am still trying to get the Type to Align with the Value,&lt;BR /&gt;&lt;BR /&gt;So the solution should look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Final_outcome; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; TYPE_1 $ TYPE_2 $ TYPE_3 $ TYPE_4 $ TYPE_5 $ TYPE_6 $ NUM_1 NUM_2 NUM_3 NUM_4 NUM_5 NUM_6; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;A A A B B C 12 8 6 8 7 9&lt;/P&gt;&lt;P&gt;A A B B C C 10 2 11 1 10 7&lt;/P&gt;&lt;P&gt;A B B B B C 7 10 9 8 1 6&lt;/P&gt;&lt;P&gt;A A B C C C 3 1 4 3 2 1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;From this you can see that one the first line&lt;BR /&gt;Originally this was&amp;nbsp;seen as:&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New"&gt;&lt;STRONG&gt;A A A&lt;/STRONG&gt; B B &lt;EM&gt;&lt;STRONG&gt;C&lt;/STRONG&gt;&lt;/EM&gt; &lt;STRONG&gt;6 8 12&lt;/STRONG&gt; 7 8 &lt;STRONG&gt;&lt;EM&gt;9&lt;/EM&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;What I am looking for is this to now be:&lt;BR /&gt;&lt;FONT face="Courier New"&gt;&lt;STRONG&gt;A A A&lt;/STRONG&gt; B B &lt;EM&gt;&lt;STRONG&gt;C&lt;/STRONG&gt;&lt;/EM&gt; &lt;STRONG&gt;12 8 6&lt;/STRONG&gt; 8 7 &lt;EM&gt;&lt;STRONG&gt;9&lt;/STRONG&gt;&lt;/EM&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;So where type 1 - 3 are A it has swapped the first three numerics to highest and lowest, from lowest to highest, not swapping all the outcomes. This is then done for the Char Type B swapping to highest - lowest and then the same for C if this had to be switch.&lt;BR /&gt;&lt;BR /&gt;Currently each&amp;nbsp;Character&amp;nbsp;is aligned to the&amp;nbsp;numeric&amp;nbsp;so if I was to just change the numeric and not the character these would not longer match to the outcome.&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Thank you,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 10:50:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-accounts-to-reverse-within-an-Array/m-p/338750#M77206</guid>
      <dc:creator>Mick_bill</dc:creator>
      <dc:date>2017-03-07T10:50:30Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting accounts to reverse within an Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-accounts-to-reverse-within-an-Array/m-p/338753#M77207</link>
      <description>&lt;P&gt;Edit: And do get into the habbit of using good programming practices - keeping code lower case, all the same case, indentented etc. &amp;nbsp;And use the {i} above your post when you want to post code to keep it separate from text.&lt;/P&gt;
&lt;P&gt;Well, I assume the character and numerics are linked somehow. &amp;nbsp;Its hard to tell from your description. &amp;nbsp;If so then the below will show a way of sorting data any way you like. &amp;nbsp;What it does is normalise the data (down rather than across, database/SAS rather than Excel), perform a sort, then transpose the data up again. &amp;nbsp;It is simpler this way as normalised data is far easier to work with programmatically than transposed data. &amp;nbsp;Also note that this code is not fixed to 6 of each, will do any number of the array.&lt;/P&gt;
&lt;PRE&gt;data original;
  input type_1 $ type_2 $ type_3 $ type_4 $ type_5 $ type_6 $ num_1 num_2 num_3 num_4 num_5 num_6;
  id=_n_;
datalines;
A A A B B C 6 8 12 7 8 9
A A B B C C 2 10 1 11 7 10
A B B B B C 7 1 8 9 10 6
A A B C C C 1 3 4 1 2 3
;
run;

data inter (keep=id type num);
  set original;
  array t{*} type_:;
  array n{*} num_:;
  do i=1 to dim(t);
    type=t{i};
    num=n{i};
    output;
  end;
run;

proc sort data=inter;
  by id num type;
run;

data want (drop=type num curr);
  set original (obs=0) inter;
  by id;
  array t{*} type_:;
  array n{*} num_:;
  retain type_: num_: curr;
  if first.id then curr=1;
  t{curr}=type;
  n{curr}=num;
  curr=curr+1;
  if last.id then output;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 10:59:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-accounts-to-reverse-within-an-Array/m-p/338753#M77207</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-03-07T10:59:48Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting accounts to reverse within an Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-accounts-to-reverse-within-an-Array/m-p/338758#M77209</link>
      <description>&lt;P&gt;I had almost the same solution as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;. I post it anyway.&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 a;
	set ORIGINAL;
	keep OBS TYPE VAL;
	array char (*) _CHARACTER_;
	array num (*) _NUMERIC_;
	do i=1 to dim(char);
		OBS=_N_;
		TYPE=char(i);
		VAL=num(i);
		output;
	end;
run;

proc sort data=a;
	by OBS TYPE DESCENDING VAL;
run;

data want;
    set a;
	format TYPE_1-TYPE_6 $1.;
	retain TYPE_1-TYPE_6 NUM_1-NUM_6;
	by OBS;
	array TYPES (*) TYPE_1-TYPE_6;
	array NUMS (*) NUM_1-NUM_6;
	do i=1 to dim(TYPES);
		if mod(_N_,6)=mod(i,6) then do;
			TYPES(i)=TYPE;
			NUMS(i)=VAL;
		end;
	end;

	if last.OBS;
	drop TYPE VAL OBS i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 11:19:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-accounts-to-reverse-within-an-Array/m-p/338758#M77209</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2017-03-07T11:19:14Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting accounts to reverse within an Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-accounts-to-reverse-within-an-Array/m-p/338779#M77219</link>
      <description>&lt;P&gt;Thank&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30622"&gt;@gamotte&lt;/a&gt;&amp;nbsp;and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;they have both worked perfectly!!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;A transpose was the way forward rather than trying to use a reversal within the array itself.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Thanks.,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Michael &lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 12:35:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-accounts-to-reverse-within-an-Array/m-p/338779#M77219</guid>
      <dc:creator>Mick_bill</dc:creator>
      <dc:date>2017-03-07T12:35:30Z</dc:date>
    </item>
  </channel>
</rss>

