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

Hi,

Hope that someone will help. 

I've a dataset 

Table entry
N_CRE RISK
5031500EUR ART127-b
5031500EUR ART127-c
00002063356EUR ART127-b
00002063356EUR ART127-d
and below the desire output
N_CRE RISK
5031500EUR ART127-b;ART127-c
00002063356EUR ART127-b;ART127-d
Please could you tell me how to do with SAS? Thanks
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20
data have;
length N_CRE RISK $20;
input N_CRE$ RISK$;
datalines;
5031500EUR ART127-b
5031500EUR ART127-c
00002063356EUR ART127-b
00002063356EUR ART127-d
;

proc sort data=have;
	by N_CRE;
run;

data want(keep=n_cre temp rename=(temp=RISK));
	set have;
	length temp $200;
	by N_CRE;
	if first.N_CRE then temp=RISK;
	else temp = cats(temp,';', RISK);

	if last.N_CRE;
	retain temp;
run;

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data as a datastep using the code window (its the {i} above post), as such I am not typing it out so just a guess:

data want (drop=_risk);
  set have (rename=(risk=_risk));
  length risk $2000;
  retain risk;
  by n_cre;
  if first.n_cre then risk=_risk;
  else risk=catx(',',risk,_risk);
  if last.n_cre then output;
run;
PeterClemmensen
Tourmaline | Level 20
data have;
length N_CRE RISK $20;
input N_CRE$ RISK$;
datalines;
5031500EUR ART127-b
5031500EUR ART127-c
00002063356EUR ART127-b
00002063356EUR ART127-d
;

proc sort data=have;
	by N_CRE;
run;

data want(keep=n_cre temp rename=(temp=RISK));
	set have;
	length temp $200;
	by N_CRE;
	if first.N_CRE then temp=RISK;
	else temp = cats(temp,';', RISK);

	if last.N_CRE;
	retain temp;
run;
foxrol94
Fluorite | Level 6

Thanks a lot.

What i've done is a:

proc sort data=have;
	by N_Cre;
run;
proc transpose data=have out=classe_risk1 (drop = _NAME_);
	by  N_Cre;
	var RISK;
run;
data classe_risk2;
	set classe_risk1;
	COL_FI = catx(';', of COL1-COL3);
run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 3 replies
  • 1726 views
  • 0 likes
  • 3 in conversation