Desktop productivity for business analysts and programmers

Understanding a code snippet from a SAS macro

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 82
Accepted Solution

Understanding a code snippet from a SAS macro

I found this code snippet in our code base:

data _null;

    file aaa;

    filename = 'xxx_123' ;

        run;

%include aaa;

filename aaa clear;

Will this run the macro xxx_123.sas and store the output in aaa and then clear it


Accepted Solutions
Solution
‎02-18-2014 05:41 PM
Super User
Super User
Posts: 6,845

Re: Understanding a code snippet from a SAS macro

No. Here is what it will do.

1) It will make a dataset name _NULL with one observation and one variable, FILENAME, with the value 'xxx_123'.

If the fileref AAA was defined before the data step then :

2A) it will be made empty since the data step writes nothing into it.

3A) it will then try to include the empty file as code and so nothing will happen.

4A) it will undefine the fileref AAA.

Otherwise

  2B)  it will create an empty file named aaa.dat in the current working directory.

  3B)  it will try to include SAS statements from a file named aaa.sas.  Effect will vary based on whether such a file exists or not.

  4B) it will get a warning trying to undefine the fileref AAA.

View solution in original post


All Replies
Solution
‎02-18-2014 05:41 PM
Super User
Super User
Posts: 6,845

Re: Understanding a code snippet from a SAS macro

No. Here is what it will do.

1) It will make a dataset name _NULL with one observation and one variable, FILENAME, with the value 'xxx_123'.

If the fileref AAA was defined before the data step then :

2A) it will be made empty since the data step writes nothing into it.

3A) it will then try to include the empty file as code and so nothing will happen.

4A) it will undefine the fileref AAA.

Otherwise

  2B)  it will create an empty file named aaa.dat in the current working directory.

  3B)  it will try to include SAS statements from a file named aaa.sas.  Effect will vary based on whether such a file exists or not.

  4B) it will get a warning trying to undefine the fileref AAA.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 358 views
  • 0 likes
  • 2 in conversation