<?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 start using the obs left from the last process? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-start-using-the-obs-left-from-the-last-process/m-p/72592#M21028</link>
    <description>Lani,&lt;BR /&gt;
&lt;BR /&gt;
maybe can create a macro variable to the end of the merge, which will be the number last used row. And then to use such a construction:&lt;BR /&gt;
data firstobs = &amp;amp;macro_variable;&lt;BR /&gt;
...&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Yuri.</description>
    <pubDate>Thu, 16 Sep 2010 08:13:20 GMT</pubDate>
    <dc:creator>rusyba</dc:creator>
    <dc:date>2010-09-16T08:13:20Z</dc:date>
    <item>
      <title>How to start using the obs left from the last process?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-start-using-the-obs-left-from-the-last-process/m-p/72591#M21027</link>
      <description>Hi all,&lt;BR /&gt;
&lt;BR /&gt;
I have two data sets A and B. &lt;BR /&gt;
Data set A (15 obs):&lt;BR /&gt;
name   &lt;BR /&gt;
---------&lt;BR /&gt;
aaa&lt;BR /&gt;
bbb&lt;BR /&gt;
ccc&lt;BR /&gt;
...          &lt;BR /&gt;
zzz   (obs #15)&lt;BR /&gt;
&lt;BR /&gt;
Data set B (10 obs):&lt;BR /&gt;
id_nbr&lt;BR /&gt;
-------------&lt;BR /&gt;
id-num1&lt;BR /&gt;
id-num2&lt;BR /&gt;
id-num3&lt;BR /&gt;
....&lt;BR /&gt;
id-num10   (obs #10)&lt;BR /&gt;
&lt;BR /&gt;
I merge the above two data sets so that my new data set will get the var id_nbr in B to be assigned for each obs in A begin with obs#1 till the last obs in B and go back to obs#1, like below:&lt;BR /&gt;
&lt;BR /&gt;
Data set New (15 obs):&lt;BR /&gt;
obs# --------- id_nbr ---------- name -------- recno&lt;BR /&gt;
1      --------- id-num1 ------- aaa ----------- 1  &lt;BR /&gt;
2      --------- id-num2 ------- bbb ----------- 2&lt;BR /&gt;
3      --------- id-num3 ------- ccc ----------- 3&lt;BR /&gt;
4&lt;BR /&gt;
5&lt;BR /&gt;
6&lt;BR /&gt;
7&lt;BR /&gt;
8&lt;BR /&gt;
9&lt;BR /&gt;
10   --------- id-num10 ------- mmm -------- 10&lt;BR /&gt;
11    --------- id-num1  ------- nnn -----------  1&lt;BR /&gt;
12&lt;BR /&gt;
13&lt;BR /&gt;
14&lt;BR /&gt;
15    --------- id-num5  ------- zzz -----------  5&lt;BR /&gt;
&lt;BR /&gt;
This is the code for the above:&lt;BR /&gt;
data new;&lt;BR /&gt;
	retain recno;&lt;BR /&gt;
	set A;&lt;BR /&gt;
	if _n_=1 or recno=10 then recno=1;&lt;BR /&gt;
	else recno+1;&lt;BR /&gt;
	run;	&lt;BR /&gt;
&lt;BR /&gt;
Now I need your help.&lt;BR /&gt;
The data set B should be used for each next run. For this run, I will have a data set named A2 that has 7 obs. I need to do like the above steps and this time I should start with what has been left in the data set B from the first run.&lt;BR /&gt;
&lt;BR /&gt;
Data set A2 (7 obs):&lt;BR /&gt;
name&lt;BR /&gt;
-----------&lt;BR /&gt;
name1&lt;BR /&gt;
name2&lt;BR /&gt;
name3&lt;BR /&gt;
name4&lt;BR /&gt;
name5&lt;BR /&gt;
name6&lt;BR /&gt;
name7&lt;BR /&gt;
&lt;BR /&gt;
After I am going to merge data set A2 and B, I should have:&lt;BR /&gt;
Data set New2  (7 obs):&lt;BR /&gt;
obs --------- id_nbr ----------- name  ----------- recno&lt;BR /&gt;
1     --------- id-num6  ------- name1 ---------- 6&lt;BR /&gt;
2     --------- id-num7  ------- name2 ---------- 7&lt;BR /&gt;
3     --------- id-num8  ------- name3 ---------- 8&lt;BR /&gt;
4     --------- id-num9  ------- name4 ---------- 9&lt;BR /&gt;
5     --------- id-num10 ------- name5 ----------10&lt;BR /&gt;
6     --------- id-num1  ------- name6 ---------- 1&lt;BR /&gt;
7     --------- id-num2  ------- name7 ---------- 2&lt;BR /&gt;
&lt;BR /&gt;
If I run again with another data set A3, it will begin with obs#3 to obs#10 (from data set B). Please give me an idea how to this.&lt;BR /&gt;
&lt;BR /&gt;
Thanks so much.&lt;BR /&gt;
Lani</description>
      <pubDate>Thu, 16 Sep 2010 07:32:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-start-using-the-obs-left-from-the-last-process/m-p/72591#M21027</guid>
      <dc:creator>Lani</dc:creator>
      <dc:date>2010-09-16T07:32:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to start using the obs left from the last process?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-start-using-the-obs-left-from-the-last-process/m-p/72592#M21028</link>
      <description>Lani,&lt;BR /&gt;
&lt;BR /&gt;
maybe can create a macro variable to the end of the merge, which will be the number last used row. And then to use such a construction:&lt;BR /&gt;
data firstobs = &amp;amp;macro_variable;&lt;BR /&gt;
...&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Yuri.</description>
      <pubDate>Thu, 16 Sep 2010 08:13:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-start-using-the-obs-left-from-the-last-process/m-p/72592#M21028</guid>
      <dc:creator>rusyba</dc:creator>
      <dc:date>2010-09-16T08:13:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to start using the obs left from the last process?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-start-using-the-obs-left-from-the-last-process/m-p/72593#M21029</link>
      <description>HTH&lt;BR /&gt;
Patrick&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%macro IterOverDs(IterDS=,OneTimeDs=); &lt;BR /&gt;
&lt;BR /&gt;
  %if not %SYMGLOBL(LastIterObs) %then&lt;BR /&gt;
  %do;&lt;BR /&gt;
    %global LastIterObs;&lt;BR /&gt;
    %let LastIterObs=0;&lt;BR /&gt;
  %end;&lt;BR /&gt;
&lt;BR /&gt;
  %global newds;&lt;BR /&gt;
  %let newds=new_&amp;amp;OneTimeDs;&lt;BR /&gt;
&lt;BR /&gt;
  data new_&amp;amp;OneTimeDs;&lt;BR /&gt;
    set &amp;amp;OneTimeDs end=last;&lt;BR /&gt;
&lt;BR /&gt;
    if _n_=1 then &lt;BR /&gt;
      CurrentIterObs=&amp;amp;LastIterObs+1;&lt;BR /&gt;
    else&lt;BR /&gt;
    if mod(CurrentIterObs,NIterObs)=0 then &lt;BR /&gt;
    do;&lt;BR /&gt;
      CurrentIterObs=1;&lt;BR /&gt;
    end;&lt;BR /&gt;
    else &lt;BR /&gt;
      CurrentIterObs+1;&lt;BR /&gt;
&lt;BR /&gt;
    recno=CurrentIterObs;&lt;BR /&gt;
&lt;BR /&gt;
    set &amp;amp;IterDS nobs=NIterObs point=CurrentIterObs;&lt;BR /&gt;
&lt;BR /&gt;
    if last then &lt;BR /&gt;
    do;&lt;BR /&gt;
      if CurrentIterObs=NIterObs then call symput('LastIterObs','0');&lt;BR /&gt;
      else call symput('LastIterObs',cats(CurrentIterObs));&lt;BR /&gt;
    end;&lt;BR /&gt;
  run;&lt;BR /&gt;
&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
%let LastIterObs=0;&lt;BR /&gt;
data iter;&lt;BR /&gt;
  do iter_var=0 to 90 by 10;&lt;BR /&gt;
    output;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data a1;&lt;BR /&gt;
  do var_a1=0 to -15 by-1;&lt;BR /&gt;
    output;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%IterOverDs(IterDS=iter,OneTimeDs=a1); &lt;BR /&gt;
&lt;BR /&gt;
title "DS is &amp;amp;newds";&lt;BR /&gt;
proc print data=&amp;amp;newds;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data a2;&lt;BR /&gt;
  do var_a1=1 to 7;&lt;BR /&gt;
    output;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%IterOverDs(IterDS=iter,OneTimeDs=a2); &lt;BR /&gt;
&lt;BR /&gt;
title "DS is &amp;amp;newds";&lt;BR /&gt;
proc print data=&amp;amp;newds;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
/* and so on and so on */</description>
      <pubDate>Thu, 16 Sep 2010 13:07:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-start-using-the-obs-left-from-the-last-process/m-p/72593#M21029</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-09-16T13:07:11Z</dc:date>
    </item>
  </channel>
</rss>

