Help using Base SAS procedures

Removing Duplicate Column Values without removing the Row

Reply
N/A
Posts: 1

Removing Duplicate Column Values without removing the Row

I was wondering If there is a way to remove duplicate column values without removing the entire row. This is purely for formatting, and i'd just like to take a step out of my manual workflow.

Basically I'd like to turn this:

LocationDepartments
Location 15400
Location 15401
Location 25402
Location 25403

Into this:

LocationDepartments
Location 15400
5401
Location 25402
5403

Thanks.

Valued Guide
Posts: 858

Re: Removing Duplicate Column Values without removing the Row

Here you go:

data have;

infile cards dsd dlm=',';

length location $10.;

input Location $ Departments $;

cards;   

Location 1,5400

Location 1,5401

Location 2,5402

Location 2,5403

;

run;

proc print data=have;id location;by location;

SAS Super FREQ
Posts: 8,742

Re: Removing Duplicate Column Values without removing the Row

Hi,

And, PROC REPORT will do this for you too.

cynthia

proc report data=have nowd;

  column location departments;

  define location / order;

  define departments /display;

run;

Trusted Advisor
Posts: 1,128

Re: Removing Duplicate Column Values without removing the Row

Alternatively you could achieve the same in a datastep by

data want;

set have;

by location;

if not first.location then location='';

run;

Thanks,

Jag

Thanks,
Jag
Ask a Question
Discussion stats
  • 3 replies
  • 234 views
  • 0 likes
  • 4 in conversation