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!
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;
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?
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
What happens when you import it?
Also, can you attach a sample file.
When I do a proc print of the imported excel file I get:
1 | ALCO Stores, Inc. ALCO Stores, Inc. ALCO Stores, Inc |
---|
that is, the repetition is put into a sequence
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;
Hi Arthur,
I did your code and it worked for my sample, here is the result:
1 | ALCO Stores, Inc. |
---|
Thanks!
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.
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.