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 9207165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:19:46+00:00 2026-06-18T00:19:46+00:00

Here’s a macro I’m writing, I want to look at a given data set,

  • 0

Here’s a macro I’m writing, I want to look at a given data set, and write of each of the field(column) names as an observation into an info data set.

Here’s what I’ve got

%macro go_macro(data);


/*get the list of field names from the dictionary*/
proc sql noprint;

    select distinct name into :columns separated by ' '
    from dictionary.columns
    where memname = "%upcase(%scan(&data, -1))" and libname = "%upcase(%scan(&data, 1))" and type = "char"
;

quit;

/*now loop through this list of fieldnames*/
%let var_no = 1; 
%let var = %scan(&columns, &var_no, ' '); 

%do %while (&var ne);

                 /*here is where I want to write the fieldname to an observation*/
    fname = "&var"; 
                 output; 


%let var_no = %eval(&var_no +1);
%let var = %scan(&columns, &var_no, ' '); 
%end;

%mend;


/*execute the code*/
data bdqa.accounts_info; 
%go_macro(braw.accounts)
run;

this gives me

[MPRINT] Parsing Base DataServer
/* 0005 */      fname = "SORT_CODE"; 
/* 0006 */          output; 
/* 0009 */      fname = "BANK_NAME"; 
/* 0010 */          output; 
/* 0013 */      fname = "CREDIT_CARD"; 
/* 0014 */          output; 
/* 0017 */      fname = "PRIMARY_ACCT_HOLDER"; 
/* 0018 */          output; 
/* 0021 */      fname = "account_close_date"; 
/* 0022 */          output;
/* 0023 */      run;


    ERROR: Parsing exception - aborting
ERROR: DS-00274 : Could not parse base DataServer code: Encountered " <ALPHANUM> "fname "" at line 5, column 9.
Was expecting one of:
    <EOF> 
    ";" ...
    "*" ...
    "data" ...
    "proc" ...
    (and 9 more)
    while

while

data mytest;

    do i = 1 to 5; 
    fname = 'hello world';
    output; 
    end;
    keep fname; 
run;

is perfectly legit.

the following code

%macro char_freqs(data=);

/*get the different variables*/
proc sql noprint;

select distinct name into :columns separated by ' '
from dictionary.columns
where memname = "%upcase(%scan(&data, -1))" and libname = "%upcase(%scan(&data, 1))" and type = "char"
;

quit;

/*now get the distinct values for each of the variables*/
%let var_no = 1; 
%let var = %scan(&columns, &var_no, ' '); 

%do %while (&var ne);

    proc freq data=&data; 
    tables &var/out=&var._freq; 
    run;    

%let var_no = %eval(&var_no +1);
%let var = %scan(&columns, &var_no, ' '); 
%end;

%mend;


%char_freqs(data=macros.businesses)

Also works – the PROC FREQ is allowed.

  • 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-18T00:19:47+00:00Added an answer on June 18, 2026 at 12:19 am

    The problem is you have something like this:

    data bdqa.accounts_info; 
    %go_macro(braw.accounts)
    run;
    

    ->

    data bdqa.accounts_info; 
    proc sql;
    ... select stuff ...;
    quit;
    fname = "stuff"; ...
    run;
    

    You need:

    proc sql;
    select stuff;
    quit;
    
    
    data bdqa.accounts_info; 
     fname = "stuff";
     ...
    run;
    

    You need to remove the PROC SQL from the macro – you can create a macro variable outside of a macro. Honestly you shouldn’t use a macro for this at all – you can do one of two things:
    a) Create the table directly from DICTIONARY.COLUMNS

    proc sql;
    create table bdqa.accounts_info as select name as fname from dictionary.columns where ... ;
    quit;
    

    b) Create it in a datastep

    data bdqa.accounts_info;
    __data = "&var_no";
    do ... ;
    run;
    

    (the do loop is basically identical to the %do loop in the macro)

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

Sidebar

Related Questions

Here is the scenario. I'm writing my geo-ruby oracle adapter for Ruby On Rails
here Html given below <div class=navBulletsWrapper> <div rel=0 class=></div> <div rel=1 class=></div> <div rel=2
here is what I am dealing with: I am given a table (Visit) with
Here's my jQuery script: $.ajax({ type: 'POST', url: 'zipCodes.php', data: searchZipCode, cache: false, success:
Here's my situation. I have a DotNetNuke application. I want to link to an
Here is the field declaration in a form: max_number = forms.ChoiceField(widget = forms.Select(), choices
Here's the situation, i want to have a user that can enter time on
here's a conundrum for you, Using Django 1.4, I cannot get messages set through
Here's the code I'm running. Basically I scrape data, and place them into simple
Here is my simplified data structure: Object1.h template <class T> class Object1 { private:

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.