BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
thesasuser
Pyrite | Level 9

I have a data set having a single column of names and 100 rows .

Is there way to combine names from every 10 rows into a string?

For example my data may be like this

aaaa

bbbb

abbc

ddda

....

...

What I want ot get is a new table with

aaaa bbbb abbbc

ddda efgh ijkl lmnop

.....

Is there a way to do it?

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

It's probably a bad idea that will only make your life harder down the road.  But it's not difficult:

 

data want;

length string $ 200;

do _n_=1 to 10 until (done);

   set have end=done;

   string = catx(' ', string, name);

end;

drop name;

run;

 

View solution in original post

3 REPLIES 3
SuryaKiran
Meteorite | Level 14

First group the data by 10 records each and then use proc transpose by the grouped variable.

 

DATA have(drop=i);
do i=1 to 200;
val=put(i,3.);
output;
end;
run;
data want;
retain group;
set have;
IF _N_=1 then group=1;
else if MOD(_N_-1,10)=0 then group+1;
run;

proc transpose data=want out=want1;
by group;
var val;
run;
Thanks,
Suryakiran
Astounding
PROC Star

It's probably a bad idea that will only make your life harder down the road.  But it's not difficult:

 

data want;

length string $ 200;

do _n_=1 to 10 until (done);

   set have end=done;

   string = catx(' ', string, name);

end;

drop name;

run;

 

thesasuser
Pyrite | Level 9
Thanks
Both solutions are wonderful and good.
Accepted this as simpler code

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!

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
  • 3 replies
  • 913 views
  • 1 like
  • 3 in conversation