SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Getting rid of comma at the end of a variable with multiple lengths

Accepted Solution Solved
Reply
Contributor
Posts: 34
Accepted Solution

Getting rid of comma at the end of a variable with multiple lengths

I imported a "|" delimited file using proc import. Import says it imported the file successfully. I checked the number of observation and looks good to me. However, the variable at the end of the dataset has ",". For e.g.:

 

VarA

Yes,

No,

1.2,

1,

3.5,

High,

 

if you could provide me a way to get rid of the "," at the end that would be great. 

 


Accepted Solutions
Solution
‎05-11-2018 04:00 PM
PROC Star
Posts: 1,605

Re: Getting rid of comma at the end of a variable with multiple lengths

Posted in reply to pmpradhan
data have;
input VarA $10.;
cards;
Yes,
No,
1.2,
1,
3.5,
High,
;

data want;
set have;
substr(vara,length(VarA),1)=' ';
run;

View solution in original post


All Replies
Solution
‎05-11-2018 04:00 PM
PROC Star
Posts: 1,605

Re: Getting rid of comma at the end of a variable with multiple lengths

Posted in reply to pmpradhan
data have;
input VarA $10.;
cards;
Yes,
No,
1.2,
1,
3.5,
High,
;

data want;
set have;
substr(vara,length(VarA),1)=' ';
run;
Contributor
Posts: 34

Re: Getting rid of comma at the end of a variable with multiple lengths

Posted in reply to novinosrin

Thank you for speedy and simple solution! Smiley Happy

Super User
Posts: 23,365

Re: Getting rid of comma at the end of a variable with multiple lengths

Posted in reply to pmpradhan

@pmpradhan wrote:

I imported a "|" delimited file using proc import. Import says it imported the file successfully. I checked the number of observation and looks good to me. However, the variable at the end of the dataset has ",". For e.g.:

 

VarA

Yes,

No,

1.2,

1,

3.5,

High,

 

if you could provide me a way to get rid of the "," at the end that would be great. 

 


PROC IMPORT guesses at what it does. It does not always guess successfully. Given that the data does not meet your requirements you're better off modifying your process to import the file cleanly in the first place. 

 

Usually you can get the code from the log and modify it. I noticed that you're posting in the DataFlux forum so I assume you're using DI studio? 

Super User
Posts: 10,700

Re: Getting rid of comma at the end of a variable with multiple lengths

Posted in reply to pmpradhan
data have;
input VarA $10.;
want=prxchange('s/,+$//',1,strip(vara));
cards;
Yes,
No,
1.2,
1,
3.5,
High,
;
proc print noobs;run;


PROC Star
Posts: 8,151

Re: Getting rid of comma at the end of a variable with multiple lengths

[ Edited ]
Posted in reply to pmpradhan

Unless you want to remove multiple commas at the end of each variable's value, I'd suggest a minor change to @Ksharp's suggested code:

data have;
  input VarA $10.;
  want=prxchange('s/,$//',1,strip(vara));
  cards;
Yes,,
No,
1.2,
1,
3.5,
High,
Other
;

Art, CEO, AnalystFinder.com

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 305 views
  • 6 likes
  • 5 in conversation