Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7889063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:00:03+00:00 2026-06-03T06:00:03+00:00

%macro name_modal(); /*Create macro variables which contain the modalities of variables*/ %do i=1 %to

  • 0
%macro name_modal();
/*Create macro variables which contain the modalities of variables*/
%do i=1 %to &num_Var;
    data _null_;
        set  &lib..Table_variable_modal_&i.;
        call symputx('num_Mod'||compress(put(&i,4.)),_N_,"G");
        call symputx('table'||compress(put(&i,4.))||'modal'||compress(put(_N_,4.)),compress(&&name_Var&i.),"G");
    run;

%end;

/*Display modalities by variable*/
%do i=1 %to &num_Var;
    %put &&name_Var&i. has &&num_Mod&i. modalities ;
    %do j=1 %to &&num_Mod&i.;
        %put %nrstr(&&tableb&i.modal&j.);
    %end;
%end;
%mend name_modal;
%name_modal();

I hope the code is self-documenting.
I’ll explain the problems here.
Everything is working fine until I pass to the second of the program which serves to display the modalities by variables.

For example when the name of modalities being stocked in the macro variables are like
$100% BLO,
100% COLOR,
AVON & RAGOBERT,
BALLANTINE’S,
L’OREAL,
AT&T,
U-V-A
etc
I fail to use %put properly.
I’ve tried using %bquote and %nrstr, but the problem persists.
So far, the only solution I can see is to modify the name of the modalities but since the names come from a client, I don’t have the possibility to make amendment on the data.

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:00:05+00:00Added an answer on June 3, 2026 at 6:00 am

    After trying a few times, I find %superq could solve this problem. Handling special characters in macro is troublesome. This page provides some useful tips on macro quoting.

    I simplified your code here to the following

    UPDATE: make it double-loop case.

    data test;
     input name ~ &  $15.;
     datalines;
     100% BLO
     100% COLOR
     AVON & RAGOBERT
     BALLANTINE'S
     L'OREAL
     AT&T
     U-V-A
     ;
    run;
    
    %macro name_modal();
    /*Create macro variables which contain the modalities of variables*/
    %do i=1 %to 4;
        data _null_;
         set  test;
         call symputx('num_Mod1',_N_,"G");
         call symputx('tableb'||compress(put(&i,4.))||'modal'||compress(put(_N_,4.)),name,"G");
        run;
    %end;
    
       %do i=1 %to 4;
        %do j=1 %to 7;
            %put %superq(tableb&i.modal&j);
        %end;
       %end;
    %mend name_modal;
    %name_modal();
    

    The result will display correctly.

    Note that it is %superq(tableb&i.modal&j) not %superq(&&tableb&i.modal&j) as superq accepts macro variable name without extra ampersand.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to create a macro which can be used for print debug messages when
I am trying to create an excel macro which is probably going to end
Is there a __CLASS__ macro in C++ which gives the class name similar to
I want to create a C macro that creates a function with a name
I have created a macro for excel which will pop up form that contains
I can call a macro from within my add-in with the following code: Application.Run(MACRO_NAME);
Is there any macro which will remove double quotes and '\0' in a string?
I am trying to call my excel macro using vbs. Here is a snippet
This macro should activate tabs in sequence from 1th to 5th and then again.
I'm creating a macro in C++ that declares a variable and assigns some value

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.