BookmarkSubscribeRSS Feed
Komal2
Calcite | Level 5
 

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.

 

%macro import_myfile(i=);
proc import file="C:\Users\komal\Desktop\Advanced SAS\Macro definition.txt" out=Macrodefinition dlm='09x' replace;
run;
%mend import_myfile;
%include Macrodefinition;

Error: Unable to complete processing of INCLUDE. Expected a filename or fileref
Failed to open macro : The system cannot find the file specified

 

Please let me know your advice on how to solve it. Thank you for your time.
12 REPLIES 12
Kurt_Bremser
Super User

@Komal2 wrote:
 

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.

 

%macro import_myfile(i=);
proc import file="C:\Users\komal\Desktop\Advanced SAS\Macro definition.txt" out=Macrodefinition dlm='09x' replace;
run;
%mend import_myfile;
%include Macrodefinition;

Error: Unable to complete processing of INCLUDE. Expected a filename or fileref
Failed to open macro : The system cannot find the file specified

 

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

Your macro definition for import_myfile is completely unnecessary. There's no dynamic code at all, parameter &i is never used. Stop making things unnecessarily complicated.

 

And a %include statement needs either a physical filename, or a file reference created by a filename statement.

Either add a statement

filename Macrodefinition "physical filename comes here";

or use the physical filename in quotes in the %include.

Astounding
PROC Star

Text files don't need to be imported.  They just need to exist.  You might use:

 

%include "C:\Users\komal\Desktop\Advanced SAS\Macro definition.txt";

 

Then any macros defined within that text file will be available.

Komal2
Calcite | Level 5
Thanks. How can I apply the 2 macros from the Txt file to HTWT. csv
dataset?


Astounding
PROC Star

That's something you need to learn.  There are multiple ways, depending on how the macros are defined.  You will need to roll up your sleeves, find some documentation and study it.  This might be a decent starting point:

 

http://documentation.sas.com/?docsetId=mcrolref&docsetTarget=n0pfmkjlc3e719n1lks4go8ke61r.htm&docset...

Komal2
Calcite | Level 5
%include "C:\Users\komal\Desktop\Advanced SAS\Macro definition.txt";

I have tried to use the code above to call the macro.

 

I am getting an error message below. I have checked the location of the file and it is correct.

 

 

Unable to compllete processing of INCLUDE. Expected a filename or fileref.

 

 

Is there something I am missing here?

Astounding
PROC Star

Just to set the record straight, this statement will not call the macro.  It will make the macro available within your program, so that later statements within the program can call the macro.

 

Let's see the log that contains the error.  That's the usual source of debugging information.

Kurt_Bremser
Super User

Please use copy and paste for logs, don't type them off the screen.

 

Unable to compllete processing of INCLUDE. Expected a filename or fileref. 

SAS logs are correctly spelled, so it would be "complete" instead of "compllete".

Copy/paste the whole log resulting from your include into a {i} window, no changes, no additions, no omissions.

Komal2
Calcite | Level 5

I am working on SAS in remote desktop. I am unable to copy/paste from SAS in remote desktop.

Komal2
Calcite | Level 5

I tried the code below to call the macro.

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)

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

Astounding
PROC Star

There are communication issues that I don't understand when you are working from a remote desktop.  How do you refer to a file from the desktop, when the file is stored elsewhere?  For a single-machine environment, it looks like you are taking all the right steps (including calling the macros).

 

Certainly for these two macros you don't need macros.  It's easy enough to code:

 

proc contents data=outcsvv;

run;

proc print data=outcsvv;

run;

 

So can I assume that these are smaller versions of what the macros actually contain?

 

 

Kurt_Bremser
Super User

I would not be surprised at all if there's some translation issue of keystrokes between the remote and local desktop, as SAS seems to misinterpret the whole filename string (including the quotes)

Reeza
Super User

Can you share your macro definitions?

I would try with a .sas file that you know is correct to see if it's a path issue or a file issue. 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 12 replies
  • 1949 views
  • 1 like
  • 4 in conversation