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.
data have;
input VarA $10.;
cards;
Yes,
No,
1.2,
1,
3.5,
High,
;
data want;
set have;
substr(vara,length(VarA),1)=' ';
run;
data have;
input VarA $10.;
cards;
Yes,
No,
1.2,
1,
3.5,
High,
;
data want;
set have;
substr(vara,length(VarA),1)=' ';
run;
Thank you for speedy and simple solution! 🙂
@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?
data have;
input VarA $10.;
want=prxchange('s/,+$//',1,strip(vara));
cards;
Yes,
No,
1.2,
1,
3.5,
High,
;
proc print noobs;run;
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
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.