Solved

Creating input to a macro variable from input table  -  SAS

Posted on 2014-04-07
3
646 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
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
Aloysius Low earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
A safe way to clean winsxs folder from your windows server 2008 R2 editions
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

10 Experts available now in Live!

Get 1:1 Help Now