DATA Step, Macro, Functions and more

Dividing the observations in to columns

Reply
Frequent Contributor
Posts: 97

Dividing the observations in to columns

hi,

i have some question......i have  100 observations.............. i want to assign every 10 observations to new column

shall  i try with firstobs , obs or

mod (_n_,10).......??

i have data like this .

NAV:

34

33

32

31

..

.

.

.

.

.

.

.

.78 (100 the observation)

want the cloulmns  as below

1_10      2_10    3 _10     4_10  5_10..........................


Regards

Allu

Super Contributor
Posts: 578

Re: Dividing the observations in to columns

Posted in reply to allurai0412

What are you wanting the value to be in the new column?  The sum of something, count of something? or is it that you would ultimately want your data like this:

1     2     3     4     5     6     7     8     9    10

11     12     13     14     15     16     17     18     19     20

21     22     23     24     25     26     27     28     29     30

Frequent Contributor
Posts: 97

Re: Dividing the observations in to columns

yes ...i need the Observation values in cloumn wise ...............

1_10   2_10    3_10............

1         11

2         12  

3         13

...        .

.           .

.           .

10        20

Regards

Allu

Super Contributor
Posts: 578

Re: Dividing the observations in to columns

Posted in reply to allurai0412

how about;;

data want;

set have;

if _N_<10 then ColName='1_10';

else if _N_ < 20 then ColName='2_10';

.

.

.

else ColName='10_10';

run;

then proc transpose on colname

Respected Advisor
Posts: 3,156

Re: Dividing the observations in to columns

Posted in reply to allurai0412

If this is what you want, if your RAM is large enough to hold your table in whole.

data have;

  do nav=1 to 99;

  output;

  end;

run;

data _null_;

  call symputx('obs', ceil(nobs/10));

  stop;

  set have nobs=nobs;

run;

data want; 

do i=1 to &obs ;

do j=1 to 10;

  set have end=last;

  array t(10,&obs.) _temporary_;

  array _(&obs.);

  t(j,i)=nav;

if last then leave;

  end;

end;

do j=1 to 10;

  do i=1 to &obs;

  _(i)=t(j,i);

  end; output;

end;

stop;

keep _:;

run;

Haikuo

Super User
Posts: 10,018

Re: Dividing the observations in to columns

Posted in reply to allurai0412

Self-merge skill is suited for your question, If your dataset is large ,using a macro variable to wrap it.

data want;

merge have(firstobs=1 obs=10 rename=(nav=nav1))

            have(firstobs=11 obs=20 rename=(nav=nav2))

..........

;

run;

Ksharp

Ask a Question
Discussion stats
  • 5 replies
  • 228 views
  • 6 likes
  • 4 in conversation