BookmarkSubscribeRSS Feed
GiMaAsh
Calcite | Level 5

So I am super new to proc sql.

My question is, can I have names of people populate in one column if they fit the condition, separated by a comma?

Like if there is a data set where people on a certain day at a certain time eat a piece of red candy, all the names of those people who fit that populate in one column separated by a comma? But still keep the other stuff like date and time distinct?

I hope I’m asking this correctly

1 REPLY 1
Kurt_Bremser
Super User

I don't think it's doable (easily) in SQL, but it's easy in a data step:

data have;
input time name $;
datalines;
1 Alfred
1 Charles
2 Susy
2 John
3 James
;

data want;
set have;
by time;
retain all_names;
length all_names $100;
if first.time
then all_names = name;
else all_names = catx(",",all_names,name);
if last.time;
drop name;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1 reply
  • 292 views
  • 1 like
  • 2 in conversation