BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ilikesas
Barite | Level 11

hi,

suppose I have the following table:

Comp Name

The company ABC

The company ABC

The company ABC

The company DEF

The company DEF

The company DEF

That is, inside each cell I have a repetition, so what I would like to obtain is the deletion of the repetition so that the new table should be as following

Comp Name
The company ABC
The company DEF

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Daniel,

Can't say for sure without seeing your sas dataset but, if your file is called have and the variable is actually imported as comp_name, then the following might do what you want:

data want (drop=_:);

  length comp_name $40;

  set have (rename=(comp_name=_c));

  comp_name=scan(_c,1,,'c');

run;

View solution in original post

6 REPLIES 6
Reeza
Super User

SAS doesn't really have cells. Is your data originally in Excel?

Does each variable/row contain the repetitive text or are they separate rows?

ilikesas
Barite | Level 11

Hi Reeza,

Actually my original data is in Excel, sorry for not mentioning that, and there in Excel each row contains the repetitive text, just as I showed in my table above.

Thanks

Reeza
Super User

What happens when you import it?

Also, can you attach a sample file.

ilikesas
Barite | Level 11

When I do a proc print of the imported excel file I get:

1ALCO Stores, Inc. ALCO Stores, Inc. ALCO Stores, Inc

that is, the repetition is put into a sequence

art297
Opal | Level 21

Daniel,

Can't say for sure without seeing your sas dataset but, if your file is called have and the variable is actually imported as comp_name, then the following might do what you want:

data want (drop=_:);

  length comp_name $40;

  set have (rename=(comp_name=_c));

  comp_name=scan(_c,1,,'c');

run;

ilikesas
Barite | Level 11

Hi Arthur,

I did your code and it worked for my sample, here is the result:

1

ALCO Stores, Inc.

Thanks!

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1564 views
  • 0 likes
  • 3 in conversation