BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

I have a string to store the path of a file, such as:C:\abc\example.csv

Suppose, Now, I have a lot of paths.
Like, C:\abc\1.csv
C:\abc\information\1.csv
C:\abc\t\aac.csv
e:\abct\b.csv
......

How can I get the filename(example) from the undefined string?
I think I can use substr to find the last '.' and position of last '/' , then get the filename.
How can I do that?

Thanks.
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
As I understand your post, you want to extract the "filename.extension" information from a complete file-path data string? If this is true, you can use the SCAN function in a DATA step with the third argument "-1" with the delimiter "\" as you have explained. If you are using the SAS macro language, you can use the function %SYSFUNC along with SCAN, as explained above.

Scott Barry
SBBWorks, Inc.

SAS.COM support website resources:

-- SAS 9.2 DOC on SCAN function:
http://support.sas.com/documentation/cdl/en/lrdict/59540/HTML/default/a000214639.htm

-- SAS Documentation web page:
http://support.sas.com/documentation/onlinedoc/base/index.html
deleted_user
Not applicable
Hi, Scott, thank you for you time.

I solved it!

Best wishes,
Jun
SunilJ
Fluorite | Level 6

Hi,

 

Can you please share, how did you solved it, as i m looking for same thing.

 

Thanks,

Sunil

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 9422 views
  • 1 like
  • 3 in conversation