2
votes

I have a text file "Macro definition" which has two SAS macros definition. I would like to import them and apply on HTWT.csv data set. This dataset has 20 observations and 6 variables ID, Gender, Age,Height,Weight,Year. All are numeric except gender variable. I have the code below to import and apply the macros from the txt file to csv file. I am getting an error message on running this code as below.

outcsvv is the name of HTWT dataset imported in SAS.

%include "C:\Users\komal\Desktop\Advanced SAS\Macro definition.txt";
%contents_of(outcsvv)
%print_data(outcsvv)
Warning:Apparent Invocation of macro "contents_of" not resolved
Error: Unable to complete processing of INCLUDE. Expected a filename or fileref
Expected a statement keyword: found "("

The second error I am getting is probably due to the macro definition(s) from the text file which are as follows.

%macro contents_of(name);
proc contents data=&name;
run;
%mend;


%macro print_data(name);
proc print data=&name;
run;
%mend;

Please let me know your advice on how to solve it. Thank you for your time.

1
Can you add the log to your question? It's unusual to put sas code in a file with .txt extension instead of .sas, but it looks to me like your code should run fine. Assuming it's running on a windows environment and the SAS session can see the files on your desktop. I don't see how the code you posted could generate that error message. I would double-check the content of Macro Definition.txt.Quentin
Some advice... if all you are doing with the macros is using them to wrap procedure calls in then you should stop and rethink what you are doing. It makes your code much harder for other people to read+use, it teaches you to use code that won't be portable to another work environment, it makes things harder to debug...Robert Penridge
Thanks. I am going to follow your suggestion Robert. For this piece of code, I have to use these macros as part of an exercise.K Bh

1 Answers

1
votes

You can setup your own macro Autocall Library. Just split your file; save one macro per-file. more.

or you can add this code to the begining of your program:

options insert=(sasautos="/C:\Users\komal\Desktop\Advanced SAS") ;

this will search for the macros in this directory.