Hello, I need to remove duplicates in a SAS dataset but don't know how to go about it. The point of the dataset is to have all CBSAs in the nation listed in the first column. Additional columns contain every CBSA which borders the first one. The problem is that the original CBSA is also always listed as a bordering one, and I need to remove it. The other problem is that the duplicate doesn't always appear in the same column. For example, I have:
CBSA CBSA_BORD1 CBSA_BORD2 CBSA_BORD3
10140 10140 16500 36500
10180 10180 15220 45020
28300 14180 27860 28300
28500 23240 28500 41700
The bold values are the duplicates, i.e. the ones I want to remove from the dataset. The problem is that I don't know which column the duplicate will necessarily be in since it changes row to row. Is there a way to search for duplicate values across rows and remove them? What I want the final dataset to look like is:
CBSA CBSA_BORD1 CBSA_BORD2
10140 16500 36500
10180 15220 45020
28300 14180 27860
28500 23240 41700
Thank you!
Hi,
It is generally better to post test data in the form of a datastep. You can use arrays on this:
data want; cbsa=10140; cbsa_bord1=10140; cbsa_bord2=16500; cbsa_bord3=36500; array cbsa_bord{3}; do i=1 to 3; if cbsa_bord{i}=cbsa then cbsa_bord{i}=.; end; run;
Hi,
It is generally better to post test data in the form of a datastep. You can use arrays on this:
data want; cbsa=10140; cbsa_bord1=10140; cbsa_bord2=16500; cbsa_bord3=36500; array cbsa_bord{3}; do i=1 to 3; if cbsa_bord{i}=cbsa then cbsa_bord{i}=.; end; run;
Perfect, don't know why I didn't think of that. Thanks so much!
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.