Hi,
Hope that someone will help.
I've a dataset
N_CRE | RISK |
---|---|
5031500EUR | ART127-b |
5031500EUR | ART127-c |
00002063356EUR | ART127-b |
00002063356EUR | ART127-d |
N_CRE | RISK |
---|---|
5031500EUR | ART127-b;ART127-c |
00002063356EUR | ART127-b;ART127-d |
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;
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;
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;
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;
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 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: