Let's say I have this dateset:
DATA foo; input a b $; datalines; 1 apple 1 banana 1 orange 2 grape 2 kiwi 3 strawberry ;
RUN
And I want to concatenate b grouping by a using PROC SQL. Maybe something like this:
PROC SQL; select concatenate(b) from foo group by a; QUIT;
How would I go about doing that with PROC FCMP?
Thank you
I'm sure one could torture PROC FCMP enough to create the function that you want. But because you want a function over several observations it will probably be very messy. Given your example, how about this data step, using the CATX function and a "SET ... BY" pair of statements inside a "do until last." loop?
DATA foo;
input a b $10.;
datalines;
1 apple
1 banana
1 orange
2 grape
2 kiwi
3 strawberry
;
RUN;
data want;
do until (last.a);
set foo;
by a;
length all_b_values $60;
all_b_values=catx(',',all_b_values,b);
end;
run;
Please vote for adding string aggregate functions to SAS/SQL at:
https://communities.sas.com/t5/SASware-Ballot-Ideas/create-string-summary-functions/idi-p/288035
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.