DATA Step, Macro, Functions and more

Macros

Reply
Frequent Contributor
Posts: 104

Macros

Dear SAS Users,

I have a macro program that follows the basic anatomy of a macro.  See sample below, The problem with this one is I can only read in one observation at a time.  What is a call routine I can use to automatically bring in a dataset with 10 observations per Var1-Var3

%macro test (var1, var2, var3) ;

data sample;

var1_new=&var1+&var2;

var2_new=&var2+&var3;

run;

%mend  test;

%test (1,2,3);

.

Respected Advisor
Posts: 3,124

Re: Macros

Not sure if I understand what you want, but adding a data step loop x10 will give your 10 obs:

%macro test (var1, var2, var3);

     data sample;

           do _n_=1 to 10;

                var1_new=&var1+&var2;

                var2_new=&var2+&var3;

                outupt;

           end;

     run;

%mend  test;

%test (1,2,3)

Haikuo

Frequent Contributor
Posts: 104

Re: Macros

I should have noted that there are different values for Var1-Var3 and the larger dataset has more than 10 obs.

Data have;

var1 var2 var3

1 2 3

4 5 6

2 8 2

4 6 3

2 3 5

and so on;

run;

Regular Contributor
Posts: 180

Re: Macros

I think you do not need a macro and what you need is the following program:

Data have;
  input var1 var2 var3;
cards;
1 2 3
4 5 6
2 8 2
4 6 3
2 3 5
;
run;

data want;
  set have;
  var1_new=var1+var2;
  var2_new=var2+var3;
run;

Regards,

avr
N/A
Posts: 1

Re: Macros

mr.hai.ko is given the correct  stmt in macros

Ask a Question
Discussion stats
  • 4 replies
  • 224 views
  • 0 likes
  • 4 in conversation