Solved

Creating input to a macro variable from input table  -  SAS

Posted on 2014-04-07
3
664 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Some of the SEO trends we might expect in 2017.
Giving access to ESXi shell console is always an issue for IT departments to other Teams, or Projects. We need to find a way so that teams can use ESXTOP for their POCs, or tests without giving them the access to ESXi host shell console with a root …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

856 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