[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Creating input to a macro variable from input table  -  SAS

Posted on 2014-04-07
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 14

Accepted Solution

Aloysius Low earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Have you ever run into that annoying problem where the computer won't boot?  Wouldn't it be great if you had a tool that would make that disk boot again?  I have found one tool that works more often than not ...
An overview of cyber security, cyber crime, and personal protection against hackers. Includes a brief summary of the Equifax breach and why everyone should be aware of it. Other subjects include: how cyber security has failed to advance with technol…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

656 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