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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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