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

Hi All,

 

I am trying to run a SAS macro that I found in the following SAS Statistics and Data Analysis Paper:

 

An Introduction to Matching and its Application using SAS.

 

I attached the paper to this post. 

 

Below are the two SAS data steps to create the input datasets for the macro. These data steps run fine. But, I cannot get the %match macro to run. 

The macro is after the two data step programs below.

 

Data CASES;
Input PTID AGMT CHK AGMN WT;
Cards;
101 39 1 13 118
102 35 1 14 129
103 28 1 12 108
104 31 1 14 110
105 41 1 13 138
;

 

Data CONTROLS;
Input PTID AGMT CHK AGMN WT;
Cards;
201 39 2 11 175
202 62 1 11 170
203 35 2 11 170
204 42 1 13 118
205 30 1 14 130
206 39 2 12 135
207 27 2 12 127
208 58 1 10 140
209 36 1 14 110
210 41 2 12 129
211 55 2 13 193
212 45 1 11 154
213 61 2 13 153
214 31 2 11 97
215 28 2 11 145
;


%match(case=CASES, control=CONTROLS, idca=PTID, idco=PTID, mvars=AGMT, wts=2, dmaxk=2,
method=optimal, ncontls=2, maxiter=10000, out=MTCH, print=y); run;

 

Can someone please help me understand why this %match macro wont run?  I get the following output when trying to run it. 

 

71 %match(case=CASES, control=CONTROLS, idca=PTID, idco=PTID, mvars=AGMT, wts=2, dmaxk=2,
-
180
WARNING: Apparent invocation of macro MATCH not resolved.
ERROR 180-322: Statement is not valid or it is used out of proper order.

72 method=optimal, ncontls=2, maxiter=10000, out=MTCH, print=y);

72 ! run;

 

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

%ds2csv is a SAS-supplied macro so is available to anyone using that SAS installation. %match appears to be a user-written macro so will only be available if the user has posted or published it so others can use it.

 

A macro always starts with a %MACRO statement and ends with a %MEND statement.

 

When you run %ds2csv, you are running a macro program that starts with the statement %MACRO  ds2csv and ends with %MEND. So for %match to work you need a similar macro program,].

View solution in original post

7 REPLIES 7
Reeza
Super User

Where is the code for the macro? Did you pull it out of the paper and include it in your code or is it available somewhere else?

To run a macro you need both the macro definition and call and then you can execute it.

Something like this:

*macro definition;
%macro print(ds=);
proc print data=&ds;
run;
%mend;



*macro call;
%print(ds=sashelp.class);



You're missing the first part of the process.

FYI - look into proc PSMATCH which is a built in SAS procedure for doing propensity score matching as well.

 


@Rover17 wrote:

Hi All,

 

I am trying to run a SAS macro that I found in the following SAS Statistics and Data Analysis Paper:

 

An Introduction to Matching and its Application using SAS.

 

I attached the paper to this post. 

 

Below are the two SAS data steps to create the input datasets for the macro. These data steps run fine. But, I cannot get the %match macro to run. 

The macro is after the two data step programs below.

 

Data CASES;
Input PTID AGMT CHK AGMN WT;
Cards;
101 39 1 13 118
102 35 1 14 129
103 28 1 12 108
104 31 1 14 110
105 41 1 13 138
;

 

Data CONTROLS;
Input PTID AGMT CHK AGMN WT;
Cards;
201 39 2 11 175
202 62 1 11 170
203 35 2 11 170
204 42 1 13 118
205 30 1 14 130
206 39 2 12 135
207 27 2 12 127
208 58 1 10 140
209 36 1 14 110
210 41 2 12 129
211 55 2 13 193
212 45 1 11 154
213 61 2 13 153
214 31 2 11 97
215 28 2 11 145
;


%match(case=CASES, control=CONTROLS, idca=PTID, idco=PTID, mvars=AGMT, wts=2, dmaxk=2,
method=optimal, ncontls=2, maxiter=10000, out=MTCH, print=y); run;

 

Can someone please help me understand why this %match macro wont run?  I get the following output when trying to run it. 

 

71 %match(case=CASES, control=CONTROLS, idca=PTID, idco=PTID, mvars=AGMT, wts=2, dmaxk=2,
-
180
WARNING: Apparent invocation of macro MATCH not resolved.
ERROR 180-322: Statement is not valid or it is used out of proper order.

72 method=optimal, ncontls=2, maxiter=10000, out=MTCH, print=y);

72 ! run;

 

Thanks

 


 

Rover17
Fluorite | Level 6

Thanks Reeza. 

 

I will try that later today. 

 

However, I was under the impression that the %match macro I asked about would function the same way as the %ds2csv macro that converts SAS datasets to CSV files. 

 

For the %ds2csv, there is no need to use the %marco and %mend statements. 

 

For example;

 

Data CASES;
Input PTID AGMT CHK AGMN WT;
Cards;
101 39 1 13 118
102 35 1 14 129
103 28 1 12 108
104 31 1 14 110
105 41 1 13 138
;

 

%ds2csv(data=CASES, csvfile='c:\CASES.csv', runmode=b);

 

 

Why do they differ?

 

Regards,

Aaron

SASKiwi
PROC Star

%ds2csv is a SAS-supplied macro so is available to anyone using that SAS installation. %match appears to be a user-written macro so will only be available if the user has posted or published it so others can use it.

 

A macro always starts with a %MACRO statement and ends with a %MEND statement.

 

When you run %ds2csv, you are running a macro program that starts with the statement %MACRO  ds2csv and ends with %MEND. So for %match to work you need a similar macro program,].

Rover17
Fluorite | Level 6

This is a great explanation on the difference between SAS supplied vs user created macros.

Regards

ballardw
Super User

If you run this code:

proc options option=set;run;

The log may show something like:

 SET=[FT15F001 = 'FT15F001.DAT'] [SASROOT = "C:\Program Files\SASHome\SASFoundation\9.4"]
[SASHOME = "C:\Program Files\SASHome"] [SASAUTOS = (                    "!SASROOT\core\sasmacro"
        "!SASROOT\aacomp\sasmacro"          "!SASROOT\accelmva\sasmacro"
"!SASROOT\dmscore\sasmacro"          "!SASROOT\graph\sasmacro"          "!SASROOT\hps\sasmacro"
       "!SASROOT\stat\sasmacro"          )] [SAMPSIO = (
"!SASROOT\core\sample"          "!SASROOT\access\sample"          "!SASROOT\accesssample\sample"
        "!SASROOT\graph\sample"          "!SASROOT\hps\sample"          "!SASROOT\hpstat\sample"
        "!SASROOT\stat\sample"          )] [SAMPsrc=(                    "!SASROOT\core\sample"
         "!SASROOT\access\sample"          "!SASROOT\accesssample\sample"
"!SASROOT\graph\sample"          "!SASROOT\hps\sample"          "!SASROOT\hpstat\sample"
"!SASROOT\stat\sample"          )] [INSTALL = (                    )] [MYSASFILES =
"?FOLDERID_Documents\My SAS Files\9.4"] [SASCFG = "C:\Program
Files\SASHome\SASFoundation\9.4\nls\en"] [SAS_NO_RANDOM_ACCESS = "1"]
                   Defines a SAS environment variable.

The relevant part starts at [SASAUTOS = . You will see a list of paths that end in SASMACRO (at least for the SAS supplied folders. The SASAUTOS option sets locations that your SAS install will search for macro names if the macro has not been compiled in the current session. If the macro name is found is found in any of those folders it will be compiled and made available for use. 

Macro program definition files will be found in those folders with the name of the macro and SAS as an extension. Your installation might include custom macros in a location other than SAS install folders and use the option SASAUTOS in your local configuration to point to additional macros. If you macro definition code does not exist in one of the SASAUTOS folders you need to compile it for each session you expect to use the macro.

 

In my case the %ds2csv macro is in C:\Program Files\SASHome\SASFoundation\9.4\core\sasmacro.

 

 


@Rover17 wrote:

Thanks Reeza. 

 

I will try that later today. 

 

However, I was under the impression that the %match macro I asked about would function the same way as the %ds2csv macro that converts SAS datasets to CSV files. 

 

For the %ds2csv, there is no need to use the %marco and %mend statements. 

 

Rover17
Fluorite | Level 6

This is also a big help. Thanks!

Reeza
Super User
The Mayo clinics macros are here but that one isn't one that's available anymore. There's a gmatch for greedy matching and vmatch.
https://bioinformaticstools.mayo.edu/?category=20

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 7 replies
  • 916 views
  • 5 likes
  • 4 in conversation