BookmarkSubscribeRSS Feed
GN0001
Barite | Level 11

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

 

 

 

 

 

 

Blue Blue
22 REPLIES 22
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
GN0001
Barite | Level 11

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

 

 

Blue Blue
PaigeMiller
Diamond | Level 26

@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?

--
Paige Miller
SASKiwi
PROC Star

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.

GN0001
Barite | Level 11

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

Blue Blue
Patrick
Opal | Level 21

@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.

 

GN0001
Barite | Level 11

Hello,

%dir_contents have documentation. If it was a company built-in Macro, there wouldn't be a docs for it.

Regards,

blueblue

 

Blue Blue
SASKiwi
PROC Star

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?

GN0001
Barite | Level 11

Hello team,

 

This is where I have found it:

 

https://www.google.com/search?q=what+does+%25+dir_contents+do+in+SAS&ei=PSN3YdvYK8T99APs3pHoCA&ved=0...

 

and it makes sense.

 

Respectfully,

blue blue

Blue Blue
Kurt_Bremser
Super User

@GN0001 wrote:

Hello team,

 

This is where I have found it:

 

https://www.google.com/search?q=what+does+%25+dir_contents+do+in+SAS&ei=PSN3YdvYK8T99APs3pHoCA&ved=0...

 

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
Barite | Level 11

Thanks for the response!

 

It gives errors.

 

How to add it?

 

Regards,

blueblue

Blue Blue
SASKiwi
PROC Star

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.  

GN0001
Barite | Level 11

Hello team,

I am not getting errors. I just asked if the macro access to the files in each path.

Regards,

BlueBlue

Blue Blue

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 22 replies
  • 1456 views
  • 9 likes
  • 6 in conversation