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

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. 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
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

5 REPLIES 5
novinosrin
Tourmaline | Level 20
data have;
input VarA $10.;
cards;
Yes,
No,
1.2,
1,
3.5,
High,
;

data want;
set have;
substr(vara,length(VarA),1)=' ';
run;
pmpradhan
Quartz | Level 8

Thank you for speedy and simple solution! 🙂

Reeza
Super User

@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? 

Ksharp
Super User
data have;
input VarA $10.;
want=prxchange('s/,+$//',1,strip(vara));
cards;
Yes,
No,
1.2,
1,
3.5,
High,
;
proc print noobs;run;


art297
Opal | Level 21

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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 5 replies
  • 1254 views
  • 6 likes
  • 5 in conversation