I have the data below. I want to keep unique make variable and concatenate all the information about the unique car maker into one row like this:
!!I want use Proc SQL only to do all the job.
Desire output:
AMC Concord 22 2012-02-19; Pacer 17 2010-09-14; Spirit 22 2011-08-17
Buick Century 20 2001-12-19; Electra 15 2003-08-02
Cuick Electra 15 2002-10-01; Century 20 2007-05-30; Spirit 22 2004-11-03
Code:
DATA cars1;
INPUT make $ model $ mpg date YYMMDD10.;
CARDS;
AMC Concord 22 2012-02-19
AMC Pacer 17 2010-09-14
AMC Spirit 22 2011-08-17
Buick Century 20 2001-12-19
Buick Electra 15 2003-08-02
Cuick Electra 15 2002-10-01
Cuick Century 20 2007-05-30
Cuick Spirit 22 2004-11-03
;
RUN;
data cars2;
set cars1;
date = put(date,yymmddn8.);
run;
What I tried so far is below:
proc sql;
create table test as
select distinct make,model, CATX (",", model,mpg) AS var1,
CATX (",", CALCULATED var1, put(date,10.)) AS var2,
monotonic() as rownum,
max(calculated rownum) as max,min(calculated rownum) as min,
case
when calculated rownum=calculated max then 2
when calculated rownum=calculated min then 1
else 0
end as record,
case
when calculated record = 1 then CATS (calculated var2)
else CATX (",", CATS (calculated var2),calculated var2)
end as result
from cars2
group by make
order by rownum;
quit;