I was trying to create a SDTM Domain using macros. I wanted to give a permanent path to store. I use %let path = "Locaton of the path";
and then %include "&path\Location of the path";
and i get an error
7 option mprint mlogic symbolgen source source2;
8 %let path = C:\Users\jasti\OneDrive\Desktop\Sdtm\DS;
9 %include "&path/C:\Users\jasti\OneDrive\Desktop\Sdtm\DS.sas";
SYMBOLGEN: Macro variable PATH resolves to C:\Users\jasti\OneDrive\Desktop\Sdtm\DS
WARNING: Physical file does not exist, C:\Users\jasti\OneDrive\Desktop\Sdtm\DS\C:\Users\jasti\OneDrive\Desktop\Sdtm\DS.sas.
ERROR: Cannot open %INCLUDE file C:\Users\jasti\OneDrive\Desktop\Sdtm\DS/C:\Users\jasti\OneDrive\Desktop\Sdtm\DS.sas.
I just started learning macros. I know i am doing dumb wrong here. Can anyone help me where am going wrong in giving the path ?
option mprint mlogic symbolgen source source2;
%let path = C:\Users\jasti\OneDrive\Desktop\Sdtm\DS;
%include "&path/C:\Users\jasti\OneDrive\Desktop\Sdtm\DS.sas";
This was the only code i started with and got error.
In your code, you're calling the path twice (once in the macro variable &path, once in the typed-out path). The two paths are being concatenated, which produces a non-existent path.
WARNING: Physical file does not exist, C:\Users\jasti\OneDrive\Desktop\Sdtm\DS\C:\Users\jasti\OneDrive\Desktop\Sdtm\DS.sas. ERROR: Cannot open %INCLUDE file C:\Users\jasti\OneDrive\Desktop\Sdtm\DS/C:\Users\jasti\OneDrive\Desktop\Sdtm\DS.sas.
Try changing your %include line to this:
%include "&path\DS.sas";
ERROR: Cannot open %INCLUDE file C:\Users\jasti\OneDrive\Desktop\Sdtm\DS/C:\Users\jasti\OneDrive\Desktop\Sdtm\DS.sas.
Look at your error and look at what you coded. It literally takes the path and puts it where you have &path so it becomes the statement above. This is not valid SAS code. That's the key to making macros initially - treat it as basic text/code generation and the code must be valid SAS code. So if you remove one of the paths below it will work, either the macro variable or the path that you've hard coded. You only need one.
%let path = C:\Users\jasti\OneDrive\Desktop\Sdtm\DS;
%include "&path/C:\Users\jasti\OneDrive\Desktop\Sdtm\DS.sas";
In your code, you're calling the path twice (once in the macro variable &path, once in the typed-out path). The two paths are being concatenated, which produces a non-existent path.
WARNING: Physical file does not exist, C:\Users\jasti\OneDrive\Desktop\Sdtm\DS\C:\Users\jasti\OneDrive\Desktop\Sdtm\DS.sas. ERROR: Cannot open %INCLUDE file C:\Users\jasti\OneDrive\Desktop\Sdtm\DS/C:\Users\jasti\OneDrive\Desktop\Sdtm\DS.sas.
Try changing your %include line to this:
%include "&path\DS.sas";
Look at the path that gets generated:
WARNING: Physical file does not exist, C:\Users\jasti\OneDrive\Desktop\Sdtm\DS\C:\Users\jasti\OneDrive\Desktop\Sdtm\DS.sas.
Would your code eventually work if you just use the &path macro variable?
%include "&path\DS.sas";
You repeat the path in the %INCLUDE statement. I would start with
%let path = C:\Users\jasti\OneDrive\Desktop\Sdtm\;
%include "&path.DS.sas";
If that does not do it, please post the %INCLUDE statement that worked before you used the macro variable.
Assuming that the file really does exist, you just need to spell it correctly. Change the "/" to "\". Then this combination would work (but would be somewhat confusing):
%let path = C:\Users\jasti\OneDrive\Desktop\Stdm\DS;
%include "&path..sas";
This would be more straightforward:
%let path = C:\Users\jasti\OneDrive\Desktop\Stdm;
%include "&path\DS.sas";
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.