Help using Base SAS procedures

Using Macro Variable that starts with "%" in a Title?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 19
Accepted Solution

Using Macro Variable that starts with "%" in a Title?

Hello -

I have a report that dynamically runs a proc-report to produce ODS output.  The columns of the report, and corresponding define statements, are dynamically populated depending on the columns that the user chooses.  However, some of these columns need to have title that start with a "%".  Using the code below, the program runs and builds the columns of the report, but when it tries to give the title of "%oftotal" to the column, the report breaks because it thinks it's looking for a macro called "oftotal".  Is there a way to suppress this warning, or make it so that the variable gets resolved without trying to invoke the "oftotal" macro?

Please help!

data work.data;

  infile datalines delimiter=',';

  format value 5. name $25.;

  input value name;

  datalines;

5,%oftotal(2013)

;

run;

data _null_;

  set work.data;

  call symputx("sortvariable", name);

run;

proc report data=work.data;

  columns value;

  define value / "&name";

run;


Accepted Solutions
Solution
‎01-08-2014 06:32 PM
Respected Advisor
Posts: 3,777

Re: Using Macro Variable that starts with "%" in a Title?

data work.data;
   infile datalines dsd;
  
informat value 5. name $25.;
  
input value name;
   call symputx("name", name);
   datalines;
5,%oftotal(2013)
;;;;
   run;

proc report data=work.data;
   columns value;
   define value / "%superQ(name)";
  
run;

View solution in original post


All Replies
PROC Star
Posts: 7,363

Re: Using Macro Variable that starts with "%" in a Title?

I'm confused.  You create a macro variable called &sortvariable, but then try to access a macro variable called &name.

Am I missing something here?

Occasional Contributor
Posts: 19

Re: Using Macro Variable that starts with "%" in a Title?

I got it backwards... I am trying to access the "sortname" macro variable... change is shown below.

data work.data;

  infile datalines delimiter=',';

  format value 5. name $25.;

  input value name;

  datalines;

5,%oftotal(2013)

;

run;

data _null_;

  set work.data;

  call symputx("sortvariable", name);

run;

proc report data=work.data;

  columns value;

  define value / "&sortvariable";

run;

Solution
‎01-08-2014 06:32 PM
Respected Advisor
Posts: 3,777

Re: Using Macro Variable that starts with "%" in a Title?

data work.data;
   infile datalines dsd;
  
informat value 5. name $25.;
  
input value name;
   call symputx("name", name);
   datalines;
5,%oftotal(2013)
;;;;
   run;

proc report data=work.data;
   columns value;
   define value / "%superQ(name)";
  
run;
Occasional Contributor
Posts: 19

Re: Using Macro Variable that starts with "%" in a Title?

This worked!  Thank you very much!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 239 views
  • 0 likes
  • 3 in conversation