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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
ballardw
Super User

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.

 

 

Astounding
PROC Star

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.

Tom
Super User Tom
Super User

@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));

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

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