BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BrahmanandaRao
Lapis Lazuli | Level 10

In sashelp.class 

I want to cancatinate name those who have same age group 

 

 

i want output as like below

 

NameSexAgeHeightWeight 
JoyceF1151.350.5 
ThomasM1157.585Joyce Thomas
JamesM1257.383 
JaneF1259.884.5 
JohnM125999.5 
LouiseF1256.377 
RobertM1264.8128James Jane John Louise  Robert
AliceF1356.584 
BarbaraF1365.398 
JeffreyM1362.584Alice Barbara  Jeffrey
AlfredM1469112.5 
CarolF1462.8102.5 
HenryM1463.5102.5 
JudyF1464.390Alfred Carol Henry 
JanetF1562.5112.5 
MaryF1566.5112 
RonaldM1567133 
WilliamM1566.5112Janet Mary Ronald William
PhilipM1672150Philip
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

proc sort data=sashelp.class out=have(keep= name age);
by age;
run;

data want;
do until(last.age);
set have;
by age;
length want $100;
want=catx(',',want,name);
end;
run;

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

So you want all the names of people who are 12 years old to be concatenated, such as this:

 

James Jane John Louise Robert

 

Is that correct, yes or no?

 

I can't imagine why anyone would want to do this, how this helps anything, how this allows you to perform more meaningful operations here, could you explain? After all, there are many ways to do this and many possible output formats, and the real solution depends on what you plan to do with this result.

 

Here is one way:

 

proc sql noprint;
    select distinct name into :names separated by ' ' from sashelp.class 
        where age=12;
quit;
%put &=names;

 

--
Paige Miller
BrahmanandaRao
Lapis Lazuli | Level 10

Tnq

Just logical and practice purpose

ballardw
Super User

@BrahmanandaRao wrote:

Tnq

Just logical and practice purpose


Practice perhaps but not so logical.

We get fair number of questions on how to deal with data provided with multiple values in a single variable and the solutions range from headachy to cumbersome or downright fragile.

novinosrin
Tourmaline | Level 20

proc sort data=sashelp.class out=have(keep= name age);
by age;
run;

data want;
do until(last.age);
set have;
by age;
length want $100;
want=catx(',',want,name);
end;
run;
BrahmanandaRao
Lapis Lazuli | Level 10
Tnq

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

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1371 views
  • 2 likes
  • 4 in conversation