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

Hi all,

 

I have a macro where the input variables are the names of the variables from a dataset to be plotted using sgplot.

 

I want to automate the axis labeling, so that the input variable name can be formatted to a string to be used in xaxis label.

I have made a proc format to convert variable names into axis labels, but not sure what to do with it.

 

If my explanation doesn't seem clear, here's psuedocode to illustrate what I'm looking for.

%macro my_macro(data, variable_name);

    %include 'path to variable name formats'

    /* Some way of using format to turn variable_name into string */

    proc sgplot 
    /* Plot stuff */
    xaxis label = /* String */ ;
    run;

%mend my_macro

   

Hope this is clear enough, thanks in advance for your help. 



 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi  @RoddyJ and welcome to the SAS Support Communities!

 

Try this simplified example:

proc format;
value $vlblfmt
'age'='Age in years'
'sex'='Gender';
run;

%macro test(var=);
proc sgplot data=sashelp.class;
vbar &var;
xaxis label="%sysfunc(putc(%lowcase(&var),$vlblfmt.))";
run;
%mend test;

%test(var=Age)
%test(var=Sex)

View solution in original post

4 REPLIES 4
FreelanceReinh
Jade | Level 19

Hi  @RoddyJ and welcome to the SAS Support Communities!

 

Try this simplified example:

proc format;
value $vlblfmt
'age'='Age in years'
'sex'='Gender';
run;

%macro test(var=);
proc sgplot data=sashelp.class;
vbar &var;
xaxis label="%sysfunc(putc(%lowcase(&var),$vlblfmt.))";
run;
%mend test;

%test(var=Age)
%test(var=Sex)
RoddyJ
Obsidian | Level 7

That's exactly what I wanted, thank you so much!

 

I have a few questions about this snippet of code and would be really grateful if you could answer them too:

 

"%sysfunc(putc(%lowcase(&var),$vlblfmt.))"
  •  Why is it enclosed in quotes, I thought putc would return the format as a string?
  • What is %lowcase doing?
  • What is %sysfunc doing?

Thanks again for your help.

FreelanceReinh
Jade | Level 19

  • Why is it enclosed in quotes, I thought putc would return the format as a string?

The LABEL= option requires quotes according to the documentation. A string is not quoted by default.


  • What is %lowcase doing?

The %LOWCASE autocall macro changes uppercase letters such as the "A" in "Age" to lowercase so that the assignment of the labels is case-insensitive. (Without that change "Age" or "AGE" would not be found in the format definition, which in my example uses only lowercase values like "age.")

  • What is %sysfunc doing?

%SYSFUNC executes the SAS function in its argument, here: the PUTC function.

RoddyJ
Obsidian | Level 7
Thanks so much for your help on this, really appreciate it.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1681 views
  • 2 likes
  • 2 in conversation