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
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
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.
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.)
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.