BookmarkSubscribeRSS Feed
monday89
Fluorite | Level 6

I have a dataset that looks like this:

 

ID group  
1 AB  
1 AB  
2 CD  
2 CD  
3 CD  
3 CD  
4 EF  

 

What i would like to do see assign 1 for unique ID with group . if it is repeated more than once, then 0

something else this

ID group count
1 AB 1
1 AB 0
2 CD 1
2 CD 0
3 CD 1
3 CD 0
4 EF 1

 

i was thinking to do proc sql like proc sql; select distinct id, group, 1 as count; quit;

 

but was wondering if there is a simple dataset command where i dont have to create another dataset

 

thanks!

 

d

1 REPLY 1
Tom
Super User Tom
Super User

COUNT is probably not a good name for a variable with values like that.  If looks like the same values as the FIRST. variable that is created for BY group processing.  Looks like both ID and GROUP have the same meaning, just that one is a number and the other is a string.

data want ;
  set have;
  by id;
  count=first.id;
run;

 

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 916 views
  • 0 likes
  • 2 in conversation