BookmarkSubscribeRSS Feed
satish123
Fluorite | Level 6

Dear all,

     Suppose i,ve a dataset containing one variable with observations from 1 to 50 (lets say). Now i need to print the output like given bellow

  subno

  1      11      21    

  2      12      22

  3      13      23

  4      14      24

  5      15      25

  6      16      26

  7      17      27

  8      18      28

  9      19      29

  10     20     30  . . . .

                         Thanks in advance.

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I suppose this ties in with your other post:

Your request is pretty simple, just merge the same dataset back for each block of 10 records, look at noobs, point and such like. 

However why would you want to, you don't seem to have any ID variables to merge by, i.e. why should 11 merge to 1 and not 2?  For your example data it makes no sense to have any merging or dataset, just do that in a loop:

data temp (drop=i j);

  array var{3} 8.;

  do j=1 to 10;

    do i=1 to 3;

      var{i}=((i-1) * 10) + j;

    end;

    output;

  end;

run;

Haikuo
Onyx | Level 15

This kind of data manipulation always makes me consider PROC TRANSPOSE. Not knowing your exact purpose (if we know what you are up to, the answer could be completely different from the beginning), here is one generic approach, I didn't use VIEW which I should, for the sake of better visibility.

options validvarname=any;

data test;

     do num=1 to 100;

           output;

     end;

run;

/*Say you want 7 records per group*/

data step_1;

     do i=1 to 7 until (last);

           set test end=last;

           grp=_n_;

           output;

     end;

run;

proc sort data=step_1 out=step_2;

     by i;

run;

proc transpose data=step_2 out=want(drop=i _name_) let;

     by i;

     id grp;

     var num;

run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Health and Life Sciences Learning

 

Need courses to help you with SAS Life Sciences Analytics Framework, SAS Health Cohort Builder, or other topics? Check out the Health and Life Sciences learning path for all of the offerings.

LEARN MORE

Discussion stats
  • 2 replies
  • 4498 views
  • 2 likes
  • 3 in conversation