Hi,
I'm want to programming a code that's is like a configuration file? I have something like this now :
and all of this statistic tools are differents marcro.sas-files (regression is one macro1.sas, another_statitics2.sas , another_statisticN.sas and so on)
and this configurations file.xlsx is depending on what you want to run for the statistics (y/n) and there for call the macros. Like this is the input for running all the statistics.
But I think this is not an good option, I want everything to be controlled by a sas-program for all the inputs, (something like pythons input()-function. Or like a check-list?
Please, do anyone have a good inspiration? I'm not a senior at programing 🙂 Maybe it is not possible? I don't even know what to search at google :S
Best regards,
(sorry my english is not my 1st language)
If your SAS session "knows" the definition of a macro all you need to run in your session is this snippet:
%executeMyProcess(
inputDataSet=sashelp.class;
,analysis2=Y
,analysis3=Y
)
(you can compare it to the situation where you are using some function in Python which was imported from a packages). So at the beginning of the session you have to tell SAS where the macro definition is stored.
In 99% cases having a macro definition inside the definition of another macro is considered bad programming practice. But in 99.9% cases calling a macro inside another macro is standard way of coding.
The way I would organise my code would be by creating a SAS Package (here is link: https://github.com/yabwon/SAS_PACKAGES). I would wrap my code from each file inside macros and then add one more "driving" macro (like the one I showed). Then at the beginning of a SAS session you, or other user would load the package, and then could run the snippet.
Bart
the input() function pops up in interactive pythons console as far as I understand that function.
In SAS case we don't have that kind "interactive" console right away.
If you have windows DMS SAS session you could use %WINDOW command to generate popping up window which can grab parameters (but it's only for DMS)
In Enterprise Guide you could set project prompts popping up at start of the process, but again it's EG specific.
xlsx file has this advantage that you can edit it easily, "double check" values before run, etc.
one more option I would consider is a "trivial" txt file with form:
paramerter1:value1
paramerter2:value2
paramerter3:value3
...
...
instead xlsx, txt file is easier to modify on every OS, does not require MS Excel, etc.
Bart
one more advantage of the "let's make a file" approach, you can have several such files created an just waiting to be used 🙂
You mean something like this:
%macro executeMyProcess(
inputDataSet=
,analysis1=N
,analysis2=N
,analysis3=N
);
%if %syperq(analysis1) = Y %then
%do;
%regression_is_one_macro1() /* from file regression_is_one_macro1.sas */
%end;
%if %syperq(analysis2) = Y %then
%do;
%another_statitics2() /* from file another_statitics2.sas */
%end;
%if %syperq(analysis2) = Y %then
%do;
%another_statisticN() /* from file another_statisticN.sas*/
%end;
/*
...
*/
%mend executeMyProcess;
%executeMyProcess(
inputDataSet=sashelp.class;
,analysis2=Y
,analysis3=Y
)
Bart
That's loos cool 😄 haven't deep dive into it yet, but at a first glance (Y) 😄
But, do I the person who is gonna use this, have to go to this macro/code and manually put Y / N then? Or can that be a pyhtons equivalite to input() . Hmm maybe a %let=y; /*put y for yes, n for no?*/ can you have a macro in a macro? ^^
If your SAS session "knows" the definition of a macro all you need to run in your session is this snippet:
%executeMyProcess(
inputDataSet=sashelp.class;
,analysis2=Y
,analysis3=Y
)
(you can compare it to the situation where you are using some function in Python which was imported from a packages). So at the beginning of the session you have to tell SAS where the macro definition is stored.
In 99% cases having a macro definition inside the definition of another macro is considered bad programming practice. But in 99.9% cases calling a macro inside another macro is standard way of coding.
The way I would organise my code would be by creating a SAS Package (here is link: https://github.com/yabwon/SAS_PACKAGES). I would wrap my code from each file inside macros and then add one more "driving" macro (like the one I showed). Then at the beginning of a SAS session you, or other user would load the package, and then could run the snippet.
Bart
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.