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-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
  • 4 replies
  • 1253 views
  • 2 likes
  • 2 in conversation