Re: Need alternative of "Filename" statement with Pipe operator for SAS University Edition and Re: Bulk Download all my files from SAS Ondemand introduce the way to read filenames recursively via modify
, replace
, and dread
without pipe
.
data i;
length i j $800;
i='!USERPROFILE\Desktop';
run;
data i;
modify i;
a=filename("i",catx("\",i,j));
a=dopen("i");
if a then do;
i=catx("\",i,j);
j="";
end;
replace;
if a;
do k=1 to dnum(a);
j=dread(a,k);
output;
end;
a=dclose(a);
a=filename("i");
run;
Usually, I use neither modify
nor replace
, but why can the code above read filenames recursively while the code below cannot?
data i;
length i j $800;
i='!USERPROFILE\Desktop';
a=filename("i",catx("\",i,j));
a=dopen("i");
if a then do;
i=catx("\",i,j);
j="";
end;
if a;
do k=1 to dnum(a);
j=dread(a,k);
output;
end;
a=dclose(a);
a=filename("i");
run;
I wonder whether the two separate data
steps are necessary.
It is not really "recursive" in the classical meaning of that term. What is is doing to appending records to the end of the dataset.
A normal data step will stop when it reads past the end of the input dataset (or input file when using INPUT statement). In this step since you are modifying the input dataset instead of writing to a new dataset the OUTPUT statements are causing extra observations to added to the input dataset. So those observations written will be read back in later in the data step and when they are directories it will lead to more observations being added.
It is not really "recursive" in the classical meaning of that term. What is is doing to appending records to the end of the dataset.
A normal data step will stop when it reads past the end of the input dataset (or input file when using INPUT statement). In this step since you are modifying the input dataset instead of writing to a new dataset the OUTPUT statements are causing extra observations to added to the input dataset. So those observations written will be read back in later in the data step and when they are directories it will lead to more observations being added.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: