Hello Team,
How can I concatenate the below data on the basis of unique dept with all the area in output?
data abc;
input dept $ area $;
datalines;
D1 a
d1 b
d1 c
d2 s
d2 d
d2 f
d3 y
d4 r
d4 f
d4 t
;
run;
Please show us the desired result.
Thank you for showing us the desired output.
If you are creating a report and you need the results as shown, then I guess @novinosrin has given you the answer. However, if you are going to do additional analysis in SAS, this is a very poor way to structure the data for analysis, so I would advise against doing this in this case.
It depends on what your next steps are.
@vishalrajpoot3 wrote:
so what would you like to suggest doing in this case?
Very simple. Don't do it. Longitudinal datasets are always better for analysis. Wide formats are only needed for presentations to PHBs.
something like this?
data abc;
input dept $ area $;
datalines;
D1 a
d1 b
d1 c
d2 s
d2 d
d2 f
d3 y
d4 r
d4 f
d4 t
;
run;
data want;
set abc;
by dept;
length new_var $30;
retain new_var;
if first.dept then call missing(new_var);
new_var=catx('-',new_var,area);
if last.dept;
run;
Hi @vishalrajpoot3 Modified my code to your requirement
data temp;
set abc;
_dept=upcase(dept);
run;
data want;
set temp;
by _dept;
length new_var $30;
retain new_var;
if first._dept then call missing(new_var);
new_var=catx(',',new_var,area);
if last._dept;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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: