DATA Step, Macro, Functions and more

Questions about getting file names by FILENAME statement

Reply
Occasional Learner
Posts: 1

Questions about getting file names by FILENAME statement

Hello everyone,

 

I am trying to get the filenames in a folder using filename statement but what if there is a single quote in my folder name?

For example, the following code:

 

filename names pipe 'dir "C:\user'name\folder\" /b';

 

It will cause an error because there is a ' (single quote) in the pathway (user'name). I don't want to change the pathway. Could anyone teach me how to make it work? 

 

Thanks!

Super User
Posts: 7,854

Re: Questions about getting file names by FILENAME statement

Get rid of that stupid quote three days before yesterday. Such characters have no place in path names, as they only cause unnecessary work.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Respected Advisor
Posts: 4,931

Re: Questions about getting file names by FILENAME statement

Double the single quote:

 

filename names pipe 'dir "C:\user''name\folder\" /b';

 

that's two single quotes between user and name.

PG
Super User
Posts: 10,044

Re: Questions about getting file names by FILENAME statement



filename names pipe dir %sysfunc(quote("C:\user'name\folder\" /b));

Super User
Posts: 10,044

Re: Questions about getting file names by FILENAME statement


filename names pipe  %sysfunc(quote(dir "C:\user'name\folder\" /b));

Ask a Question
Discussion stats
  • 4 replies
  • 107 views
  • 2 likes
  • 4 in conversation