- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Can you retype your question so it is readable? At least insert some line breaks.
For blocks of code use the Insert Code or Insert SAS Code icon on the edit window menu bar to get a pop-up window where you can insert or edit the blocks of code so that the formatting is preserved.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Sorry! Not sure what happened that the format completely changed in the post. Try again here.
I have the following
MACRO %_LINKEX (DATA1=aa, DATA2=bb, LMIN=2);
%_BY (DOB,FN1,LN1);
%_VAR (P_FN1,P_LN1);
%_RUN;
The variable I have are: FN1, FN2, LN1, LN2 P_FN1, P_FN2, P_LN1, P_LN2
If I have to do it individually, I basically have to run 16 combinations.
eg. combination 1: FN1, LN1 with P_FN1, P_LN1
combination2: FN1, LN2 with P_FN1, P_LN1.
I have another macro which was used in another program, like this:
%MACRO COMPARE(FN, NFN, LN, NLN);
(%DO C = 1 %TO &NFN; %DO A= 1 %TO &FLN;
(&FN.&F=&LN.&L AND &FN.&F IS NOT NULL)
%IF &F = &NFN AND &L = &NLN %THEN %DO;
%END; %ELSE %DO;OR %END; %END; %END;)
%MEND COMPARE;
I was wondering how I can combine the two so that I don't need to run 16 times of each combination. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Show us the SAS code you want to create for a single instance, and define which parts need to be made dynamic so they can be used as macro parameters.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%_LINKEX (DATA1=aa, DATA2=bb, LMIN=2);
%_BY (DOB,FN1,LN1);
%_VAR (P_FN1,P_LN1);
%_RUN;
DATA link1;
set _LKD
_TIE;
run;
I basically will have link1-link16 and join them together and dedup.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Another problem I just realized that each time the macro will generate two files: _LKD and _TIE.
If I insert another macro in it, I may just get the last combination instead of the all of them together....
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@GingerJJ wrote:
%_LINKEX (DATA1=aa, DATA2=bb, LMIN=2);
%_BY (DOB,FN1,LN1);
%_VAR (P_FN1,P_LN1);
%_RUN;
DATA link1;
set _LKD
_TIE;
run;
I basically will have link1-link16 and join them together and dedup.
What you posted looks like calls to 4 different macros followed by a data step. You have not show any definitions for any of these four macros.
The macro language in SAS is used to generate SAS code.
What is the SAS code you are trying to run? How can the macro processor help you generate that code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What those this mean?
I basically will have link1-link16 and join them together and dedup.
Are you saying you want to combine 16 datasets and get the unique set of observations?
data all;
set link1-link16;
run;
proc data data=all nodupkey ;
by _all_;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@GingerJJ wrote:
%_LINKEX (DATA1=aa, DATA2=bb, LMIN=2);
%_BY (DOB,FN1,LN1);
%_VAR (P_FN1,P_LN1);
%_RUN;
DATA link1;
set _LKD
_TIE;
run;
I basically will have link1-link16 and join them together and dedup.
That's just macro calls, we need to see the code you want to create wirh those macros, and the code of the macros themselves, so we can point out what goes wrong.
If these are macros you downloaded from somewhere, see the documentation there, and call for the developer's help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Are you seriously trying to use the ancient MACRO statement instead of the normal %MACRO statement?
If so your syntax does not appear to be valid
667 MACRO ERROR: Old-style macro name % must contain only letters, digits, and underscores. 667 ! %_LINKEX (DATA1=aa, DATA2=bb, LMIN=2); 668 669 %_BY (DOB,FN1,LN1); --- 180 ERROR 180-322: Statement is not valid or it is used out of proper order. WARNING: Apparent invocation of macro _VAR not resolved. 670 671 %_VAR (P_FN1,P_LN1); - 180 ERROR 180-322: Statement is not valid or it is used out of proper order. WARNING: Apparent invocation of macro _RUN not resolved. 672 673 %_RUN; - 180 ERROR 180-322: Statement is not valid or it is used out of proper order.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
LINKEX is package for the purpose of data linkage.
I don't know if I understand what you mean by ancient or normal. I'm pretty new to MACRO
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What are you trying to do? Packages isn't a term that's used in SAS really.
Is LINKEX an internal macro to your company that you're trying to use? Did you find it somewhere? Can you share the code?
I genuinely have no idea what that code above could be doing right now.....and I've programmed in SAS for almost 2 decades.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you're new to macros here are some references.
Generally, macros inside macros is a no. You can call macros within macros but you shouldn't define macros within macros.
General guideline to making macros is first have working code, then figure out how to generalize it. Can you show how your code would be if there were no macros?
UCLA introductory tutorial on macro variables and macros
https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/
Tutorial on converting a working program to a macro
This method is pretty robust and helps prevent errors and makes it much easier to debug your code. Obviously biased, because I wrote it 🙂 https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md
Examples of common macro usage
https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Ap...
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@GingerJJ wrote:
LINKEX is package for the purpose of data linkage.
I don't know if I understand what you mean by ancient or normal. I'm pretty new to MACRO
What is LINKEX? How does it work? We cannot help you with something we know nothing about.
Here is the only LINKEX I could find and it has nothing to with programming, let alone SAS programming.
https://trackapkg.com/linkex-tracking-number