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

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 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
  • 9081 views
  • 1 like
  • 3 in conversation