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;

 

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

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
  • 1010 views
  • 0 likes
  • 2 in conversation