Creating input to a macro variable from input table  -  SAS

Posted on 2014-04-07
Last Modified: 2016-02-10

I have a table that has one column which is a list of numbers.  Is there a way to read this table one row at a time and use the information as input to a macro variable in SAS.  Because the numbers can change they cannot be hardcoded into the %MEND



Results I am trying to get reading in TableA
%Macro Rep(FieldA)

   Lines of Code

Question by:morinia
  • 2
LVL 14

Accepted Solution

Aloysius Low earned 500 total points
ID: 39983321
2 ways to go about this:
1. use call execute
2. read the values into multiple macro variables then loop the macro variables to call the macro

1. Using call execute
data _null_;
  set tableA;
  call execute('%rep(' || trim(left(fieldA)) || ');');

2. reading into multiple macro variables and loop them
data _null_;
  set tableA;
  call symput("var" || put(_N_, best.), fieldA);
  call symput("count", _N_);

%macro loop;
  %do i = 1 %to &count;


Author Comment

ID: 39983613

I am still working through the macro loop.  I am confused on how to loop the macro variables to call the macro.

If I want to create a table for each variable from the input file.  How would I loop through to get that?

 Data Table_&&var&i;
  Set File_b;
    If sex = 'F';
LVL 14

Expert Comment

by:Aloysius Low
ID: 39984817
you'll need to surround the statements with a macro like the macro loop that i wrote above:

%macro yourloop;
  %do i = 1 %to &count;
     Data Table_&&var&i;
       Set File_b;
       If sex = 'F';

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Scenario: Your operations manager has discovered an anomaly in your security system. The business will start to suffer within 15 minutes if it is a major IT incident. What should she do? We have 6 recommendations for managing major incidents (https:…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now