BookmarkSubscribeRSS Feed
Calcite | Level 5

I have a dataset where I need to make sure that each like ID gets assigned the same Value. It's not so much that I need to select a specific value to repeat from all that are assigned to the like ID, but that I need all the like IDs to have the same Value. 

Data Have:

 Id   Value
101   656
101   756
101   805
101   752      
501   999
502   405
502   365

 Data Want:

 Id   Value   Selected
101   656     656
101   756     656
101   805     656
101   752     656   
501   999     999
502   405     999
502   365     999 


Diamond | Level 26
data want;
    set have;
    by id;
    retain selected;
    if then selected=value;
Paige Miller
SAS Employee

Suppose you had the chosen values in a dataset have2 (completely made up based on the values you're displaying):

ID  Selected
101 656
501 999
502 999

Then a PROC SQL left join will do the trick:

proc sql;
    select, t1.value, t2.selected
    from have as t1 left join have2 as t2
    on =;




Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

From SAS Users blog
Want more? Visit our blog for more articles like these.
5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1 like
  • 3 in conversation