<?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: Switching Order of 2 Data Rows: PROC SQL or DO LOOP or array? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Switching-Order-of-2-Data-Rows-PROC-SQL-or-DO-LOOP-or-array/m-p/770993#M244595</link>
    <description>&lt;P&gt;Why?&lt;/P&gt;
&lt;P&gt;From your photograph is looks like there is a variable EXSEQ that is controlling the order with-in the higher order sorting.&lt;/P&gt;
&lt;P&gt;So is the real question how to change EXSEQ=1 to 2 and EXSEQ=2 to 1 for that given subject?&lt;/P&gt;</description>
    <pubDate>Tue, 28 Sep 2021 18:54:23 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-09-28T18:54:23Z</dc:date>
    <item>
      <title>Switching Order of 2 Data Rows: PROC SQL or DO LOOP or array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Switching-Order-of-2-Data-Rows-PROC-SQL-or-DO-LOOP-or-array/m-p/770934#M244564</link>
      <description>&lt;P&gt;How do I switch the order of 2 rows (_n_=8 &amp;amp; _n_=9) without compromising the rest of the dataset?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dimpz429_0-1632844673068.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64199i4A3AB3EA43726D8C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dimpz429_0-1632844673068.png" alt="dimpz429_0-1632844673068.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=exsrc2 out=exsrc3;
	by STUDYID USUBJID EXTRT EXSTDTC;
run;

data exsrc4;
	EXSEQ=0;
	format &amp;amp;varlist;
	do until (last.USUBJID);
	set exsrc3;
	by USUBJID;
	EXSEQ+1;
	output;
	end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I feel like the solution should be really easy (PROC SQL; update? or a data step &amp;amp; multiple DO loops) but I'm struggling. Please help!! Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Sep 2021 16:43:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Switching-Order-of-2-Data-Rows-PROC-SQL-or-DO-LOOP-or-array/m-p/770934#M244564</guid>
      <dc:creator>anonymous_user</dc:creator>
      <dc:date>2021-09-28T16:43:19Z</dc:date>
    </item>
    <item>
      <title>Re: Switching Order of 2 Data Rows: PROC SQL or DO LOOP or array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Switching-Order-of-2-Data-Rows-PROC-SQL-or-DO-LOOP-or-array/m-p/770950#M244572</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@anonymous_user&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;How do I switch the order of 2 rows (_n_=8 &amp;amp; _n_=9) without compromising the rest of the dataset?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dimpz429_0-1632844673068.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64199i4A3AB3EA43726D8C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dimpz429_0-1632844673068.png" alt="dimpz429_0-1632844673068.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=exsrc2 out=exsrc3;
	by STUDYID USUBJID EXTRT EXSTDTC;
run;

data exsrc4;
	EXSEQ=0;
	format &amp;amp;varlist;
	do until (last.USUBJID);
	set exsrc3;
	by USUBJID;
	EXSEQ+1;
	output;
	end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I feel like the solution should be really easy (PROC SQL; update? or a data step &amp;amp; multiple DO loops) but I'm struggling. Please help!! Thank you.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;One way using Firstobs and Obs= dataset options:&lt;/P&gt;
&lt;PRE&gt;data example;
   do row= 1 to 15;
   output;
   end;
run;

data want;
  set example (firstobs=1 obs=7)
      example (firstobs=9 obs=9)
      example (firstobs=8 obs=8)
      example (firstobs=10)
  ;
run;&lt;/PRE&gt;
&lt;P&gt;Firstobs sets the observation number (row or _n_ value) as the first read, obs= sets the observation number to end getting data from the data set. With no Obs set the default value (max) means the remainder of the data is read.&lt;/P&gt;
&lt;P&gt;Note the OBS= is the observation number, not the number of records to read. So when Firstobs=Obs value then one record is read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Sep 2021 16:54:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Switching-Order-of-2-Data-Rows-PROC-SQL-or-DO-LOOP-or-array/m-p/770950#M244572</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-09-28T16:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: Switching Order of 2 Data Rows: PROC SQL or DO LOOP or array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Switching-Order-of-2-Data-Rows-PROC-SQL-or-DO-LOOP-or-array/m-p/770993#M244595</link>
      <description>&lt;P&gt;Why?&lt;/P&gt;
&lt;P&gt;From your photograph is looks like there is a variable EXSEQ that is controlling the order with-in the higher order sorting.&lt;/P&gt;
&lt;P&gt;So is the real question how to change EXSEQ=1 to 2 and EXSEQ=2 to 1 for that given subject?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Sep 2021 18:54:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Switching-Order-of-2-Data-Rows-PROC-SQL-or-DO-LOOP-or-array/m-p/770993#M244595</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-28T18:54:23Z</dc:date>
    </item>
    <item>
      <title>Re: Switching Order of 2 Data Rows: PROC SQL or DO LOOP or array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Switching-Order-of-2-Data-Rows-PROC-SQL-or-DO-LOOP-or-array/m-p/771003#M244598</link>
      <description>&lt;P&gt;THANK YOU so much!!! It worked. OBS vs FIRSTOBS is such a beginning programming topic --- I forgot about it.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Sep 2021 19:18:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Switching-Order-of-2-Data-Rows-PROC-SQL-or-DO-LOOP-or-array/m-p/771003#M244598</guid>
      <dc:creator>anonymous_user</dc:creator>
      <dc:date>2021-09-28T19:18:27Z</dc:date>
    </item>
    <item>
      <title>Re: Switching Order of 2 Data Rows: PROC SQL or DO LOOP or array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Switching-Order-of-2-Data-Rows-PROC-SQL-or-DO-LOOP-or-array/m-p/771004#M244599</link>
      <description>&lt;P&gt;Thank you for pointing that out! I followed the metadata instructions for creating the EXSEQ variable, so those programming instructions don't line up with the original dataset. I was trying to recreate the "ex" dataset. That's why I asked how to flip the order of 2 rows distinctly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I appreciate the help highlighting the constraint of the EXSEQ ordering---gah!&lt;/P&gt;</description>
      <pubDate>Tue, 28 Sep 2021 19:21:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Switching-Order-of-2-Data-Rows-PROC-SQL-or-DO-LOOP-or-array/m-p/771004#M244599</guid>
      <dc:creator>anonymous_user</dc:creator>
      <dc:date>2021-09-28T19:21:08Z</dc:date>
    </item>
  </channel>
</rss>

