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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

New Learning Events in April

 

Join us for two new fee-based courses: Administrative Healthcare Data and SAS via Live Web Monday-Thursday, April 24-27 from 1:00 to 4:30 PM ET each day. And Administrative Healthcare Data and SAS: Hands-On Programming Workshop via Live Web on Friday, April 28 from 9:00 AM to 5:00 PM ET.

LEARN MORE

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