Reputation: 95
Hi there pretty simple question I think, I have a record like this for example :
name value
Mack 12
Mack 10
Mack 50
Now I want to put all the value in a variable or a single row. The result should be
value_concat
12,10,50
I try to use the first and last statement with SAS but it not working for me here is what I wrote :
data List_Trt1;
set List_Trt;
by name;
if first.name then value_concat = value;
value_concat = cats(value_concat,",",value);
if last.name then value_concat = cats(value_concat,",",value);
run;
Thank you for the help!
Upvotes: 0
Views: 117
Reputation: 63434
You're on the right track.
data List_Trt1;
set List_Trt;
by name;
length value_concat $30; *or whatever is appropriate;
retain value_concat;
if first.name then value_concat=' ';
value_concat=catx(',',value_concat,value);
if last.name then output;
run;
First, you need retain so it keeps its value throughout. Second, you need to initialize it to blank on first.name
. Third, you need to output only on last.name
. I use CATX
because it is more appropriate to what you are doing, but your CATS
should be okay also.
Upvotes: 2