BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
melhaf
Fluorite | Level 6

Hi,

 

I'm want to programming a code that's is like a configuration file? I have something like this now :

Capture.PNG

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)

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

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

 

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

6 REPLIES 6
yabwon
Onyx | Level 15

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 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



yabwon
Onyx | Level 15

one more advantage of the "let's make a file" approach, you can have several such files created an just waiting to be used 🙂

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



melhaf
Fluorite | Level 6
hello, i don't want it to be a file, i want to have something like this but you say y/n, input dates (from, to) in sas - maybe as a macro? I don't want to have excel at all
yabwon
Onyx | Level 15

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



melhaf
Fluorite | Level 6

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? ^^ 

yabwon
Onyx | Level 15

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

 

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 6 replies
  • 662 views
  • 1 like
  • 2 in conversation