loops - SAS: Return to previous observation in SAS Data Step possible? -


i asked question on runsubmit too, since sas q&a community seems bit scattered. if not appreciated, please let me know.

is possible in data step return previous/certain observation , go there further through data set?

to add question in case still not clear, small example:

data set 'work.test' :

name  |   number    john  |    1       jack  |    2   jane  |    3      jade  |    4        ronn  |    5        dick  |    6        sofy  |    7       sady  |    8       ruth  |    9       

data step:

data _null_;  set work.test;  file ...\test.txt;  put name;  if number = 5 , counter=3 do;    counter = counter+1;    *return obs number = 3* aka *set obs pointer obs nr=3*;  end; run; 

*the question part return obs number = 1 , not [and first time] , added not generate , endless loop.*

additional info:
seems still not 100% clear want do, added bit original sample data set , example. remember should bit generic , not fixed code. conditions might vary later on. main question just: "is possible go obs=x , go there when @ obs=y , how?"

background info: fits whole story of creating xml output using single table holding xml flow, elements need repeated. no, not possible using xml map because of old sas version. no, ods not applicable in case. btw, background info because remark 'i still don't knwo try do' keeps coming ;)

list of possibilities not applicable needs:

  • rewind function (returns first observation)
  • lag function (to previous value of variable, not going in obs)
  • using multiple set statements: not generic in way need (ie. data sets require 2 loops, others require 5 loops, 5 nested set statements...)

what work:

  • use of complete scl code go through data step (postponed)
  • point option in set statement (current try out)
  • hash tables: still have more research not know or how implement.

the set statement of executable type.

/* test data */ data one;   input name $ num; cards; john 1  jack 2  jane 3  jade 4 ; run;  /* output obs until num=3 output */ data two;    until (num=3 or end1);       set 1 end=end1;       output;    end;    until (end2);       set 1 end=end2;       output;    end;    stop; run;  /* check */ proc print data=two; run; /* on lst obs    num    name   1      1     john  2      2     jack  3      3     jane  4      1     john  5      2     jack  6      3     jane  7      4     jade */ 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -