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

x
?
Solved

Creating input to a macro variable from input table  -  SAS

Posted on 2014-04-07
3
Medium Priority
?
717 Views
Last Modified: 2016-02-10
Experts,

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

Example.  

TableA
FieldA
001
002
005
010

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

   Lines of Code

%MEND
%Rep(001)
%Rep(002)
%Rep(005)
%Rep(010)
0
Comment
Question by:morinia
[X]
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
3 Comments
 
LVL 14

Accepted Solution

by:
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)) || ');');
run;


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

%macro loop;
  %do i = 1 %to &count;
    %rep(&&var&i);
  %end;
%mend;

%loop;
0
 

Author Comment

by:morinia
ID: 39983613
Lowaloysius,

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';
run;
0
 
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';
     run;
  %end;
%mend;
0

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