Thanks for sharing your code, and sample data.
You code is very close to working. I only see two problems.
In the SQL step, you are using count(*) grouped by ID and Type. This will tell you that there are two records for jan class1 and one record for jan class2. But it doesn't tell you that there are two different values of TYPE for jan. For that, you can use count(distinct(type)) grouped by ID.
In the data step, you need to increase the length of ID, or the value will be truncated.
I think this code will give what you want:
data one;
input ID$ Type$ origin$;
datalines;
jan class1 UK
jan class1 UAE
jan class2 US
feb class3 INDIA
feb class3 MIDEAST
mar class4 NORWAY
;
run;
Proc sql;
create table temp as
Select *,count (distinct(Type)) as N from one
group by ID;
quit;
data two;
length ID $12 ;
set temp;
if N>1 then ID=cats(ID,Type);
run;
proc print data=two ;
run ;
Look here:
Bart
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.