Hello!
For reporting purposes, I am trying to get a list of files from a directory as a variable in a sas dataset. I am using the following code to access a test directory (unfortunately I can't show the actual filenames in the actual directory, so below has a lot of dummy code/placeholders):
filename pipedir pipe "dir test/users/documents" lrecl=5000;
data test;
infile pipedir truncover;
input line $char1000.;
put line;
run;
However, instead of one filename per obs, the variable line in work.test has 4 filenames per obs:
Here's how work.test should look:
I tried 'dlm=".doc"' and 'dlm=" "', but I was not able to fix it. Does anyone have any suggestions?
Thank you in advance.
Best,
Yawen
What operating system is your SAS code running on? Check the macro variables SYSSCP and SYSSCPL.
Your output looks like the output of ls on unix to a terminal.
But if you are using Unix why did you use dir instead of ls as the command?
Also when piped to another process ls will automatically generate only one name per line.
Try using ls instead of dir as the command.
Hi,
add the /b parameter and enclose your path in double quotes like in
filename pipedir pipe "dir ""C:\temp\*.*"" /b" lrecl=5000;
- Cheers -
Use SAS on-board tools:
data filenames;
length
fref $8
fname $200
;
rc = filename(fref,"test/users/documents");
did = dopen(fref);
if did ne 0
then do;
do i = 1 to dnum(did);
fname = dread(did,i);
output;
end;
rc = dclose(did);
end;
rc = filename(fref,"");
keep fname;
run;
What operating system is your SAS code running on? Check the macro variables SYSSCP and SYSSCPL.
Your output looks like the output of ls on unix to a terminal.
But if you are using Unix why did you use dir instead of ls as the command?
Also when piped to another process ls will automatically generate only one name per line.
Try using ls instead of dir as the command.
It's amazing that you realized I was programming in a unix environment. Thank you so much!
I guess they set up an alias for the ls command called dir, for the people coming over from Windows.
@Kurt_Bremser wrote:
I guess they set up an alias for the ls command called dir, for the people coming over from Windows.
It must be something other than an alias. The ls command knows when it is being piped and adjusts how it displays multiple names.
On my Red Hat Linux server someone has installed a dir command that appears to be from the GNU library. It seems to behave like the symptom in this question.
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!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.