SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
djbateman
Lapis Lazuli | Level 10

I am trying to get a list of files in a specified directory, but I have noticed that when using the command prompt syntax that I cannot use directories that contain a space.  Does anyone know of a way to get my code to work with spaces?  The code should return about 300 files, but I'm getting 0.

 

%let dir=S:\cdm\Programming\445\106\Data Cleaning\MDR\MDR Standard Checks\Part B\AE;
%let ext=xlsx;

filename EXTlist pipe "dir /b /s &dir.\*.&ext.";

data directory;
	infile EXTlist truncover;
	input directory $200.;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

Better in my opinion to leave the macro variable unquoted, and quote when used.

%let dir=S:\cdm\Programming\445\106\Data Cleaning\MDR\MDR Standard Checks\Part B\AE;
%let ext=xlsx;

filename EXTlist pipe "dir /b /s ""&dir.\*.&ext"" ";

data directory;
	infile EXTlist truncover;
	input directory $200.;
run;

 

View solution in original post

4 REPLIES 4
SASKiwi
PROC Star

My understanding is you need quotes around paths that include spaces. How about this?

%let dir=%str(%')S:\cdm\Programming\445\106\Data Cleaning\MDR\MDR Standard Checks\Part B\AE;
%let ext=xlsx%str(%');
ChrisNZ
Tourmaline | Level 20

Better in my opinion to leave the macro variable unquoted, and quote when used.

%let dir=S:\cdm\Programming\445\106\Data Cleaning\MDR\MDR Standard Checks\Part B\AE;
%let ext=xlsx;

filename EXTlist pipe "dir /b /s ""&dir.\*.&ext"" ";

data directory;
	infile EXTlist truncover;
	input directory $200.;
run;

 

djbateman
Lapis Lazuli | Level 10

I knew it was some kind of quoting issue, but I couldn't figure out how many quotes to use, and if they should be single or double.  This method did the trick.  Thanks!

RichardDeVen
Barite | Level 11

Windows filenames can contain ampersands.  You will want to be sure SAS does not try to use the & as a resolution directive.

 

Example:

Wrap path in %NRSTR for explicit assignment.  Use %SUPERQ to resolve the symbol only.

%let path = %nrstr(c:\temp\tom&jerry videos);

filename dir pipe "dir /b /s ""%superq(path)""";

data _null_;
  infile dir;
  input;
  put _infile_;
run;

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1358 views
  • 4 likes
  • 4 in conversation