SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
smackerz1988
Pyrite | Level 9

Hello,

 

I have a macro I am working on that requires a template list of texts/prompts that can be used and then subsequently modified based on what is required. so basically the macro call would be

 

%macro(text=" ");

However, I  want a drop down list that can be modified after text so something like

 

%macro( text="Do this <insert instruction>"
             "Do that < insert instruction>"
             "Describe this <insert object>");

I see there is custom tasks in SAS Studio or insert prompt and SAS EG but the issue I'm having is that you store the list in a macro and then add it to the macro. However I have to run it and then select the pre-populated values.  

%macro(text=&list.);

 Is there a way I can just bring up the template values that I can modify prior to running the macro or is that functionality not currently possible? 

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15
%macro test(parameter,insert_code)/minoperator;

  %if %superq(PARAMETER) = %then
    %do;
      %put NOTE: This is a help info form macro &sysmacroname.;
      %put NOTE- The PARAMETER parameter allows only the below;
      %put NOTE- list of values for actions:; 
      %put NOTE- `explain` for: "I want you to act as a code explainer in SAS. I don't understand this function. Can you please explain what it does, and provide an example? {Insert Code}";
      %put NOTE-;
      %put NOTE- `optimize` for "I want you to act as a code optimizer in SAS. {Describe problem with current code, if possible}. Can you make the code {cleaner/more efficient/run faster/more readable}? {Insert Code}";
    %goto EndOfMacro;
    %end;

  %if NOT (%superq(PARAMETER) in (explain optimize)) %then
    %do;
      %put ERROR: The PARAMETER parameter has bad value!;
      %test()
    %goto EndOfMacro;
    %end;


%put THE CODE: %superq(insert_code);


%EndOfMacro:
%mend test;

%test()

%test(explain, (data test123; set sashelp.class; do i=1,2,3; put i; end; run;))

%test(blabla)
_______________
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

4 REPLIES 4
yabwon
Onyx | Level 15

1) why you will need a drop down list if you are going to use it like that:

 

%macro(text=&list.);

 

?

 

2) maybe macro design with testing + minoperator can do the job:

%macro test(parameter)/minoperator;

  %if %superq(PARAMETER) = %then
    %do;
      %put NOTE: This is a help info form macro &sysmacroname.;
      %put NOTE- The PARAMETER parameter allows only the following;
      %put NOTE- list of values:; 
      %put NOTE- Aaa;
      %put NOTE- Bbb;
      %put NOTE- Ccc;
    %goto EndOfMacro;
    %end;

  %if NOT (%superq(PARAMETER) in (Aaa Bbb Ccc)) %then
    %do;
      %put ERROR: The PARAMETER parameter has bad value!;
      %test()
    %goto EndOfMacro;
    %end;


  data &PARAMETER;
    set sashelp.class;
  run;


%EndOfMacro:
%mend test;

?

 

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



smackerz1988
Pyrite | Level 9

@yabwon Okay full context I want to use it to create SAS specific template list of prompts for a ChatGPT Macro to use within SAS to get the most efficiency (or attempt to) so I wanted to create prompts such as this.

 

"I want you to act as a code explainer in SAS. I don't understand this function. Can you please explain what it does, and provide an example? {Insert Code}" so you could ask PROC FCMP or PROC HTTP
"I want you to act as a code optimizer in SAS. {Describe problem with current code, if possible}. Can you make the code {cleaner/more efficient/run faster/more readable}? {Insert Code}"

 

So a user can choose from a drop down list (albeit a partially modifiable drop down list)  and then modify/tailor based on their particular issue/requirements  

 

 

 

 

yabwon
Onyx | Level 15
%macro test(parameter,insert_code)/minoperator;

  %if %superq(PARAMETER) = %then
    %do;
      %put NOTE: This is a help info form macro &sysmacroname.;
      %put NOTE- The PARAMETER parameter allows only the below;
      %put NOTE- list of values for actions:; 
      %put NOTE- `explain` for: "I want you to act as a code explainer in SAS. I don't understand this function. Can you please explain what it does, and provide an example? {Insert Code}";
      %put NOTE-;
      %put NOTE- `optimize` for "I want you to act as a code optimizer in SAS. {Describe problem with current code, if possible}. Can you make the code {cleaner/more efficient/run faster/more readable}? {Insert Code}";
    %goto EndOfMacro;
    %end;

  %if NOT (%superq(PARAMETER) in (explain optimize)) %then
    %do;
      %put ERROR: The PARAMETER parameter has bad value!;
      %test()
    %goto EndOfMacro;
    %end;


%put THE CODE: %superq(insert_code);


%EndOfMacro:
%mend test;

%test()

%test(explain, (data test123; set sashelp.class; do i=1,2,3; put i; end; run;))

%test(blabla)
_______________
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



sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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