BookmarkSubscribeRSS Feed
Dontik
Obsidian | Level 7

Hello!

I have a following problem. What I have right now:

ID V1 V2 V3
1 x    
1 x    
1 x    
1   x  
1   x  
1   x  
1     x
1     x
1     x
2 x    
2   x  
2     x
3 x    
3 x    
3   x  
3   x  
3     x
3     x
4 x    
4 x    
4   x  
4   x  
4     x
4     x


What I would like to get:

ID V1 V2 V3
1 x x x
1 x x x
1 x x x
2 x x x
3 x x x
3 x x x
4 x x x
4 x x x

 

I'd be grateful!

Dan

4 REPLIES 4
Reeza
Super User

What about update?

 

Not sure it would keep the correct amount of,records though, you may need to add a counter to uniquely identify iterations. 

 

Data want;

update have(obs=0) have;

by id counter;

run;

 

data should be:

 

id counter 

1 1

1 2

1 3

1 1

1 2

1 3

2 1

2 1

...etc 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

The question is, why do you have data like that, it looks to me like some step previous to this is the real cause of the issue.  Fixing the data before you get into this position would be my suggestion.

Astounding
Opal | Level 21

Here's an approach that would work for numeric variables V1, V2, and V3:

 

data want;

merge have (where=(v1 > .)) have (where=(v2 > .)) have (where=(v3 > .));

by id;

run;

 

If any of these variables are character instead, you would have to change the corresponding WHERE condition (switch from > . to > ' ').

 

You will still get a message about a many-to-many match, but the results will be OK.  ("OK" might be open to interpretation if you have differing numbers of values, like 3 observations with a V1 value for an ID, but only 2 observations with a V2 value.)

LinusH
Tourmaline | Level 20
Another fix could be using SQL GROUP BY and max().
Data never sleeps

SAS INNOVATE 2024

Innovate_SAS_Blue.png

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 772 views
  • 3 likes
  • 5 in conversation