BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Quentin
Super User

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 ;
The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 16 replies
  • 1824 views
  • 0 likes
  • 7 in conversation