Hi,
I am trying to create a macro for proc format as I have many variables that can be formatted in similar matter. However, I have 2 problems/questions.
1. Is there a way I could use a comma in my macro without SAS thinking it is an additional parameters?
%macro man_e(i,j,k);
value &&i.
1 = "&&j."
2 = "Did not &&k.";
%mend;
%man_e(MAN,Appointed surviving spouse of X, of Y or of Z,appoint surviving spouse of X, of Y or of Z);
2. Can I use an apostrophe in the macro? It would be very useful as a lot a apostrophe are used in French
%man20_e(MAN_20Ae,au niveau d'entrée);
Thank you in advance!
You should be able to solve both at once, by adding double-quotes when you call the macro. For example:
%macro man_e (i, j, k);
value &i.
1 = &j.
2 = &k.;
%mend;
proc format;
%man_e (MAN, "Appointed surviving spouse of X, of Y or of Z", "Did not appoint surviving spouse of X, of Y or of Z")
That makes it more readable, and allows you to use commas and apostrophes, with one small downside. You have to type the words "Did not" as part of the value of your third parameter.
1. Sure you can do this, but I don't see how this is any less typing or any easier than typing PROC FORMAT for your cases without the macros. If you must have a comma, use the %str() function.
2. Look up the %STR and %NRSTR function in SAS, there are examples there of including apostrophe's in your macro
You might look into creating a data set for use with the cntlin option to create formats.
Your I parameter would be the FMTNAME, your J and K parameters would be used to create the LABEL and the values 1 and 2 would be Start.
You should be able to solve both at once, by adding double-quotes when you call the macro. For example:
%macro man_e (i, j, k);
value &i.
1 = &j.
2 = &k.;
%mend;
proc format;
%man_e (MAN, "Appointed surviving spouse of X, of Y or of Z", "Did not appoint surviving spouse of X, of Y or of Z")
That makes it more readable, and allows you to use commas and apostrophes, with one small downside. You have to type the words "Did not" as part of the value of your third parameter.
@Shawn08 wrote:
Hi,
I am trying to create a macro for proc format as I have many variables that can be formatted in similar matter. However, I have 2 problems/questions.
1. Is there a way I could use a comma in my macro without SAS thinking it is an additional parameters?
%macro man_e(i,j,k); value &&i. 1 = "&&j." 2 = "Did not &&k."; %mend; %man_e(MAN,Appointed surviving spouse of X, of Y or of Z,appoint surviving spouse of X, of Y or of Z);
2. Can I use an apostrophe in the macro? It would be very useful as a lot a apostrophe are used in French
%man20_e(MAN_20Ae,au niveau d'entrée);
Thank you in advance!
I am not sure what you mean for (1) but if the issue is how to pass in a list of values then just use something other than comma as your delimiter. For example you could use | as the delimiter.
%macro man_e(fmtname,values);
%local i ;
value &fmtname
%do i=1 %to %sysfunc(countw(&values,|));
&i = %sysfunc(quote(&qscan(&values,&i,|)))
%end;
;
%mend;
For (2) add quoting. Either write the macro to expect a quoted string.
%man20_e(MAN_20Ae,"au niveau d'entrée");
Or add macro quoting.
%man20_e(MAN_20Ae,%bquote(au niveau d'entrée));
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.