BookmarkSubscribeRSS Feed
allurai0412
Fluorite | Level 6

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

5 REPLIES 5
DBailey
Lapis Lazuli | Level 10

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

allurai0412
Fluorite | Level 6

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

DBailey
Lapis Lazuli | Level 10

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

Haikuo
Onyx | Level 15

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

Ksharp
Super User

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 898 views
  • 6 likes
  • 4 in conversation