BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASKiwi
PROC Star

"Especially in the face of large-scale projects, it is necessary to use proc DS2, macro, and FCMP cross-use". I'm with @LinusH here as I don't understand why you think you need to use all three of these together. It would help if you could explain your use case in more detail why these are required.

 

I too work on large-scale projects and have never found a need to go beyond "normal"  macros.

yabwon
Onyx | Level 15

"Embedding a macro definition into the middle of a data step [...] makes no sense." - I dare to dissagre 😉

 

If you want to create a macro with a "dynamic" name that may be the case:

data _null_;
  do i = "A", "B", "C";
    rc = resolve('%macro ' !! i !! '(); %put NOTE:[&sysmacroname.]; 
                  title "&sysmacroname."; 
                  data &sysmacroname.; 
                  set sashelp.class(obs=3);  
                  run; 
                  proc print;
                  run;
                  %mend;');
  end;
run;

%A()

%B()

%C()

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



_Sas_Beginner_
Quartz | Level 8
perferly!may be your answer is top!I love this answer!
yabwon
Onyx | Level 15

I'm using this trick in the MacroArray package (https://github.com/SASPAC/macroarray) to create dynamically named macros which are calling macro array lists.

 

For example, the `%ABC` macro is generated automatically inside of %array()macro:

  %array(ABC[17] (111:127), macarray=Y); 
  
  %macro test();
    %do i = 1 %to 17; 
      %put &i.) %ABC(&i.); 
    %end;
  %mend;
  %test() 
  
  %let %ABC(13,i) = 99999;

  %do_over(ABC, phrase=%nrstr( 
      %put &_i_.%) %ABC(&_i_.); 
      ),
      which = 1:H:2
  );

 

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



Tom
Super User Tom
Super User

The macro pre-processor is for code generation.  If you are going to use the data step for the code generation then what is the need for the macro definition?  Just generate the code you want instead of trying to generate code that can generate the code you want.

yabwon
Onyx | Level 15

I'm not saying I want to use data step for code generation, I'm just saying that there is a justified use case when inserting macro definition inside a data step makes sense. 

The power, or the effect of synergy, from the  4GL and Macro language is that we can "interleave" them. Macro creates data step, data step creates macro, macro calls data step, data step calls macro, and my favourite (from Mike Rhoads' article Use the Full Power of SAS in Your Function-Style Macros) macro calls user defined function which calls a macro. 🙂

 

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
  • 21 replies
  • 1530 views
  • 4 likes
  • 6 in conversation