<?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: Skipping every 3rd line when  _n_ is given to us in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Skipping-every-3rd-line-when-n-is-given-to-us/m-p/311814#M67494</link>
    <description>&lt;P&gt;Macro variables can be used (obviously, I guess).&amp;nbsp; But they can become lengthy, and you have to make sure that numbers greater than 999 don't contain any commas.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Look how easy it is to do if you have a data set such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data rows;&lt;/P&gt;
&lt;P&gt;input rownum;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;P&gt;8&lt;/P&gt;
&lt;P&gt;10&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now retrieving the observations is easy:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set rows;&lt;/P&gt;
&lt;P&gt;rownum = rownum + 3;&lt;/P&gt;
&lt;P&gt;set a1 point=rownum;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With 452 numbers, or with 45,200 numbers the final DATA step doesn't need to change.&lt;/P&gt;</description>
    <pubDate>Tue, 15 Nov 2016 18:35:59 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-11-15T18:35:59Z</dc:date>
    <item>
      <title>Skipping every 3rd line when  _n_ is given to us</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skipping-every-3rd-line-when-n-is-given-to-us/m-p/311759#M67465</link>
      <description>&lt;P&gt;Dear All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I am trying to solve this problem . This is how far i have done. the row numbers are given to us and we want to skip to the 3rd line after the given row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data a1;&lt;/P&gt;&lt;P&gt;infile datalines;&lt;BR /&gt;input x name $ ;&lt;BR /&gt;datalines;&lt;BR /&gt;1 aa&lt;BR /&gt;2 bb&lt;BR /&gt;3 cc&lt;BR /&gt;4 dd&lt;BR /&gt;5 ee&lt;BR /&gt;6 ff&lt;BR /&gt;7 gg&lt;BR /&gt;8 hh&lt;BR /&gt;9 ii&lt;BR /&gt;10 jj&lt;BR /&gt;11 kk&lt;BR /&gt;12 ll&lt;BR /&gt;13 mm&lt;BR /&gt;14 nn&lt;BR /&gt;15 oo&lt;BR /&gt;16 pp&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;the given row numbers are 2, 8 , 10. so when these row numbers are given. I want to skip to the 3rd line. For example when _n_= 2 i want to skip to the 3rd line under it and pick x= 5 &amp;amp; name = ee&amp;nbsp;&lt;/P&gt;&lt;P&gt;here _n_= 8 is given so skip to 11th line and pick x=11 &amp;amp; name = kk&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output i want is as under&amp;nbsp;&lt;/P&gt;&lt;P&gt;x &amp;nbsp; name&amp;nbsp;&lt;/P&gt;&lt;P&gt;5 &amp;nbsp; &amp;nbsp;ee&lt;/P&gt;&lt;P&gt;11 &amp;nbsp;kk&lt;/P&gt;&lt;P&gt;13 &amp;nbsp;mm&lt;/P&gt;&lt;P&gt;my code which is incomplete as under.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let list = 2, 8, 10; /* &amp;nbsp;The list may have hundreds of numbers, here i only chose 3 */&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;set a1;&lt;BR /&gt;if _N_ in (&amp;amp;list.)then do ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't know how to skip to 3rd line from here&lt;/P&gt;&lt;P&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate your help in this regard.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank You&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2016 16:22:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skipping-every-3rd-line-when-n-is-given-to-us/m-p/311759#M67465</guid>
      <dc:creator>athapa1183</dc:creator>
      <dc:date>2016-11-15T16:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: Skipping every 3rd line when  _n_ is given to us</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skipping-every-3rd-line-when-n-is-given-to-us/m-p/311767#M67470</link>
      <description>&lt;P&gt;A better solution will probably be given but this should work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro foo;
	%let list = 2 8 10; /*  The list may have hundreds of numbers, here i only chose 3 */

	%let exclude=;
	%do i=1 %to %sysfunc(countw(&amp;amp;list.));
		%let n=%scan(&amp;amp;list.,&amp;amp;i.,' ');
		%let exclude=&amp;amp;exclude %eval(&amp;amp;n.+1) %eval(&amp;amp;n.+2);
	%end;

	%put &amp;amp;exclude;

	data test;
		set a1;

		if _N_ not in (&amp;amp;exclude.);
	run;
%mend foo;

%foo;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Nov 2016 16:42:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skipping-every-3rd-line-when-n-is-given-to-us/m-p/311767#M67470</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2016-11-15T16:42:15Z</dc:date>
    </item>
    <item>
      <title>Re: Skipping every 3rd line when  _n_ is given to us</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skipping-every-3rd-line-when-n-is-given-to-us/m-p/311775#M67474</link>
      <description>&lt;P&gt;It does not produce the output you want but i dont understant how exactly it should work.&lt;/P&gt;
&lt;P&gt;If, from 8 you skip to 11, you should not take the 10 in your list into account and thus&lt;/P&gt;
&lt;P&gt;keep the 12th row.&lt;/P&gt;
&lt;P&gt;On the other hand, if you take the 10 into account, the 11th observation should not be in the output.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2016 16:52:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skipping-every-3rd-line-when-n-is-given-to-us/m-p/311775#M67474</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2016-11-15T16:52:32Z</dc:date>
    </item>
    <item>
      <title>Re: Skipping every 3rd line when  _n_ is given to us</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skipping-every-3rd-line-when-n-is-given-to-us/m-p/311792#M67485</link>
      <description>&lt;P&gt;You would be responsible for making sure the numbers are legitimate.&amp;nbsp; For example, you couldn't have 15 in the list, when there are only 16 observations to choose from.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let list=2, 8, 10;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;do i=&amp;amp;list;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; rownum = i+3;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set a1 point=rownum;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;stop;&lt;/P&gt;
&lt;P&gt;drop i;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's probably easier if you forget about a macro variable, and keep the row numbers in a SAS data set.&amp;nbsp; If it makes sense to you, we can explore that in more detail.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2016 17:34:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skipping-every-3rd-line-when-n-is-given-to-us/m-p/311792#M67485</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-11-15T17:34:34Z</dc:date>
    </item>
    <item>
      <title>Re: Skipping every 3rd line when  _n_ is given to us</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skipping-every-3rd-line-when-n-is-given-to-us/m-p/311809#M67492</link>
      <description>&lt;P&gt;Thank you. Yes the numbers are not this close they are apart by more than 20&amp;nbsp;rows.&lt;/P&gt;&lt;P&gt;The last number still will have at least 20&amp;nbsp;rows under it.&lt;/P&gt;&lt;P&gt;Thank you so much the Code works perfectly fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;Can you please explain why it is easy not to use a macro variable. I have 452 such numbers in the list . the total rows are 495,955 and the numbers in the list range from 302,000 to 494,918(last number in the list).&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2016 18:22:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skipping-every-3rd-line-when-n-is-given-to-us/m-p/311809#M67492</guid>
      <dc:creator>athapa1183</dc:creator>
      <dc:date>2016-11-15T18:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: Skipping every 3rd line when  _n_ is given to us</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skipping-every-3rd-line-when-n-is-given-to-us/m-p/311810#M67493</link>
      <description>&lt;P&gt;Thank you for helping out. Sorry this was just the sample. yes there will be at least 20 rows under each number. They will not overlap&amp;nbsp;as my example.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2016 18:25:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skipping-every-3rd-line-when-n-is-given-to-us/m-p/311810#M67493</guid>
      <dc:creator>athapa1183</dc:creator>
      <dc:date>2016-11-15T18:25:11Z</dc:date>
    </item>
    <item>
      <title>Re: Skipping every 3rd line when  _n_ is given to us</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skipping-every-3rd-line-when-n-is-given-to-us/m-p/311814#M67494</link>
      <description>&lt;P&gt;Macro variables can be used (obviously, I guess).&amp;nbsp; But they can become lengthy, and you have to make sure that numbers greater than 999 don't contain any commas.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Look how easy it is to do if you have a data set such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data rows;&lt;/P&gt;
&lt;P&gt;input rownum;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;P&gt;8&lt;/P&gt;
&lt;P&gt;10&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now retrieving the observations is easy:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set rows;&lt;/P&gt;
&lt;P&gt;rownum = rownum + 3;&lt;/P&gt;
&lt;P&gt;set a1 point=rownum;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With 452 numbers, or with 45,200 numbers the final DATA step doesn't need to change.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2016 18:35:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skipping-every-3rd-line-when-n-is-given-to-us/m-p/311814#M67494</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-11-15T18:35:59Z</dc:date>
    </item>
    <item>
      <title>Re: Skipping every 3rd line when  _n_ is given to us</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skipping-every-3rd-line-when-n-is-given-to-us/m-p/311818#M67497</link>
      <description>&lt;P&gt;UNDERSTOOD. Thank you it really Helps.&lt;/P&gt;&lt;P&gt;Have a nice day.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2016 18:47:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skipping-every-3rd-line-when-n-is-given-to-us/m-p/311818#M67497</guid>
      <dc:creator>athapa1183</dc:creator>
      <dc:date>2016-11-15T18:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: Skipping every 3rd line when  _n_ is given to us</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skipping-every-3rd-line-when-n-is-given-to-us/m-p/311822#M67500</link>
      <description>&lt;P&gt;If you have 445 number it will be hard to put all those numbers in the list. If you can create a dataset for the numbers you want It is more efficient using HASH Tables. Take the 445 numbers dataset in-memory and match merge using HASH Objects.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FYI: &lt;A href="http://support.sas.com/resources/papers/proceedings09/071-2009.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings09/071-2009.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2016 18:51:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skipping-every-3rd-line-when-n-is-given-to-us/m-p/311822#M67500</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2016-11-15T18:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: Skipping every 3rd line when  _n_ is given to us</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skipping-every-3rd-line-when-n-is-given-to-us/m-p/311827#M67502</link>
      <description>&lt;P&gt;I'm looking into it. Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2016 19:09:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skipping-every-3rd-line-when-n-is-given-to-us/m-p/311827#M67502</guid>
      <dc:creator>athapa1183</dc:creator>
      <dc:date>2016-11-15T19:09:33Z</dc:date>
    </item>
  </channel>
</rss>

