I have a dataset in SAS and I want to Convert one column into string by the Product. I have attached the image of input and output required. I need the Colomn STRING in the outut. can anyone please help me ?
Asked
Active
Viewed 1,516 times
1
-
Stackoverflow is not a code writing service. What have you tried ? What errors or unexpected output did you get ? – Richard May 25 '18 at 13:19
-
@Richard I tried with RETAIN function but it was not working as expected. Next time, I will provide the code as well for the context. – 21Rahul May 28 '18 at 07:41
2 Answers
1
I have coded a data step to create the input data:
data have;
input products $
dates
value
;
datalines;
a 1 0
a 2 0
a 3 1
a 4 0
a 5 1
a 6 1
b 1 0
b 2 1
b 3 1
b 4 1
b 5 0
b 6 0
c 1 1
c 2 0
c 3 1
c 4 1
c 5 0
c 6 1
;
Does the following suggested solution give you what you want?:
data want;
length string $ 20;
do until(last.products);
set have;
by products;
string = catx(',',string,value);
end;
do until(last.products);
set have;
by products;
output;
end;
run;
0
Here's my quick solution.
data temp; length cat $20.; do until (last.prod); set have; by prod notsorted; cat=catx(',',cat,value); end; drop value date; run; proc sql; create table want as select have.*, cat as string from have inner join temp on have.prod=temp.prod; quit;