Hello team,
I have inherited SAS code that I need to understand:
This the code: %dir_contents (dir=&mypath., ext=, dsoub=theseFiles, attribs=N);
The top captures all files names from the requested directory, and the file names as observations within a SAS dataset.
When I run this code:
it gives me 3 variables. basefile, pathname, file_seq
and it has 3 rows.
Are these 3 fields named automatically?
The next line of the code is:
1-
Proc sql;
delete from thislibname.control where sentfile in (select distinct basefile from thesefiles);
run;
Regarding 1, this code reaches to files inside folders in a directory, not the folders that reside inside the directory. It goes one layer deep.
%while dir_contents is the list of files in a directory.
Can anyone talk about this and resolve this difference?
Regards,
blueblue
We don't know what the macro %dir_contents does, but yes, the macro must be assigning the names to the variables.
If you need more detail about what the macro is doing, please post the code of the macro and state your questions clearly.
Hello PaigeMiller,
Thanks for the response.
I will tell you what it does:
It creates a list of files in a directory and stores them in SAS dataset. It creates 3 variables for output:
basefile, pathname and file_seq.
This is the output:
basefile pathname file_seq
fileA /dataset1/...... 1
fileB /dataset2/...... 2
fileC /dataset2/...... 3.
I wonder if this macro access the files which resides in fileA, because from the codes following this %dir_contents, that is what can be understood.
The code is: proc sql; delete from production.table1 where filename in (select distinct basefile from myfiles).
Hope this makes sense.
Respectfully,
blueblue
@GN0001 wrote:
Hello PaigeMiller,
Thanks for the response.
I will tell you what it does:
It creates a list of files in a directory and stores them in SAS dataset. It creates 3 variables for output:
basefile, pathname and file_seq.
This is the output:
basefile pathname file_seq
fileA /dataset1/...... 1
fileB /dataset2/...... 2
fileC /dataset2/...... 3.
I wonder if this macro access the files which resides in fileA, because from the codes following this %dir_contents, that is what can be understood.
The code is: proc sql; delete from production.table1 where filename in (select distinct basefile from myfiles).
Can we see the entire code from this macro?
What is your question?
Is there no one in your company who can explain to you how these company-developed macros work? If you have to ask the Community how macros developed in your own company work then somebody is not doing their job when handing them over to you.
Hello,
%dir_contents is not a company developed macro. It is a built-in Macro in SAS.
The code works well and they didn't hand over their job to me. They want me to learn how to write code in future.
Regards,
blueblue
@GN0001 wrote:
Hello,
%dir_contents is not a company developed macro. It is a built-in Macro in SAS.
The code works well and they didn't hand over their job to me. They want me to learn how to write code in future.
It is NOT a built-in SAS macro and though also not documented in SAS documentation.
"...they didn't hand over..." If "they" is SAS consulting then this makes such a macro still not "built-in".
If you add option mautolocdisplay; to your code then the SAS log will tell you where the .sas file with the macro code is taken from.
Hello,
%dir_contents have documentation. If it was a company built-in Macro, there wouldn't be a docs for it.
Regards,
blueblue
I just checked for this macro at documentation.sas.com and didn't find it. It also doesn't exist on our SAS installation. I'm curious to know where you found documentation for it. Could it be a third-party add-on?
Hello team,
This is where I have found it:
and it makes sense.
Respectfully,
blue blue
@GN0001 wrote:
Hello team,
This is where I have found it:
and it makes sense.
Respectfully,
blue blue
So this macro comes from a PharmaSUG paper. You MUST read and understand this paper to use the macro.
@GN0001 wrote:
Hello,
%dir_contents have documentation.
Where? Post the URL.
Thanks for the response!
It gives errors.
How to add it?
Regards,
blueblue
If you are getting an error like this when calling the macro:
ERROR 180-322: Statement is not valid or it is used out of proper order.
It means it doesn't exist and you need to get the source code for it.
Hello team,
I am not getting errors. I just asked if the macro access to the files in each path.
Regards,
BlueBlue
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.