BookmarkSubscribeRSS Feed
xtan2
Calcite | Level 5

Hello. Everyone,

 

My code to import the file is 
 
Proc Import Datafile = 'D:\STAT_8020_Advanced_SAS\HW4\new.year2010.csv'
DBMS = csv
Out = sasuser.newyear2010
Replace;
Run;
 
Data newyear2010;
Set sasuser.newyear2010;
Run;
 
 I have successfully created and stored the following macro for creating a linear regression:
 
libname Doc 'C:\Users\thisi\Documents';
Options mstored sasmstore = Doc;
%macro slreg(dataset, dep=, indep=)/store source;
Proc Reg Data= &dataset;
Model &dep = &indep;
Run;
%mend;
 
It could be easily called using 
%slreg(newyear2010, dep=sale, indep=day)
 
However, when I tried to call it using the %include procedure in this following code:
%include 'C:\Users\thisi\Documents\slreg.sas' /source2;
it was not successful.
 
The SAS log error message is 
115 %include 'C:\Users\thisi\Documents\slreg.sas' /source2;
WARNING: Physical file does not exist, C:\Users\thisi\Documents\slreg.sas.
ERROR: Cannot open %INCLUDE file C:\Users\thisi\Documents\slreg.sas.
 
When I tried to call it using the Proc Catalog procedure in this following code, it was also unsuccessful:
Filename slreg Catalog 'Doc.Sasmacr';
%include slreg / source2;
 
The SAS log is
117 Filename slreg Catalog 'Doc.Sasmacr';
118 %include slreg / source2;
ERROR: For sequential access, physical name must be at least 3 levels.
ERROR: Cannot open %INCLUDE file SLREG.
 
Would you like to give me some hint about the possible solution?
Thank you very much!
 
8 REPLIES 8
PaigeMiller
Diamond | Level 26
115 %include 'C:\Users\thisi\Documents\slreg.sas' /source2;
WARNING: Physical file does not exist, C:\Users\thisi\Documents\slreg.sas.
ERROR: Cannot open %INCLUDE file C:\Users\thisi\Documents\slreg.sas.

You cannot refer to a folder/file that does not exist. You have to refer to a folder/file that does exist. If you look in Windows Explorer, you will see that no file named slreg.sas exists in the folder.

 

Your macro is not stored as a SAS file. It is stored in a SAS catalog named DOC. I believe you should just call the macro, without %include.

--
Paige Miller
xtan2
Calcite | Level 5

Hello. Paige,

Thank you for your reply.
Actually, both this folder path 

C:\Users\thisi\Documents\

and the catalog sasmacr exist.

xtan2_0-1615567024543.png

This is why the error seems confusing.

PaigeMiller
Diamond | Level 26

@xtan2 wrote:

Hello. Paige,

Thank you for your reply.
Actually, both this folder path 

C:\Users\thisi\Documents\

and the catalog sasmacr exist.



"catalog sasmacr exist" — but that's not what I said. And that's not what you told SAS to look for.

 

SAS is looking for a file named slreg.sas in that folder. Why? Because that's what you said to look for in the %include statement. And it's not in there.

 

You can access your macro without %include. Just use

 

%slreg(newyear2010, dep=sale, indep=day)

without any %include (you may have to restart SAS, because it is now looking for the %slreg macro elsewhere, perhaps there is a way to eliminate this problem without restarting SAS, but I am not aware of the method).

--
Paige Miller
xtan2
Calcite | Level 5

Yes. I have successfully use this code: 

%slreg(newyear2010, dep=sale, indep=day)

It works well.

But we were asked to do the following:

 

 In the year2010 data, consider sale as your response variables, day as your independent variable. Write a sas macro for simple linear regression by considering (sale and day as the dependent and independent variable) and store it. Call this regression by following approaches 

  1. %include
  2. Catalog access method

When I tried to call the saved macro of slreg, none of the strategies have worked. So I posted my question here.

PaigeMiller
Diamond | Level 26

To get %include to work, you specifically have to save the macro in a file named slreg.sas in that folder. It doesn't work if there isn't a file named slreg.sas in that folder.

--
Paige Miller
xtan2
Calcite | Level 5

This is the confusing point: I have already created the macro slreg and it exists:

 

xtan2_0-1615569146057.png

Do I have to change the type of this macro from Macro into SAS?

 

PaigeMiller
Diamond | Level 26

You want a file type of .sas


Changing the file type of the file you just showed will not work. You have to save the macro as text, with file name slreg.sas

--
Paige Miller
Reeza
Super User

Is the image of the "sasmacr" that makes you think your file is there?

 

That's a catalog file, not a .sas file. I would recommend changing your Windows viewer settings so you can see the extensions on the file or add the file type in the viewer. Then you'll see the file type is not a SAS program file, it's a SAS catalog with an extension of sas7bcat. So your %include is looking for a file with the extension ".sas". It will be the program file from your first post,  saved to the location below. 

 

So the %INCLUDE doesn't work because there is no .sas file there.

 

This is how that solution would work:

 

%include 'path to .sas file with macro code';

%slreg(newyear2010, dep=sale, indep=day);

 

 


@xtan2 wrote:

Hello. Paige,

Thank you for your reply.
Actually, both this folder path 

C:\Users\thisi\Documents\

and the catalog sasmacr exist.

xtan2_0-1615567024543.png

This is why the error seems confusing.


 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 997 views
  • 0 likes
  • 3 in conversation