BookmarkSubscribeRSS Feed
sophia_SAS
Obsidian | Level 7

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);

.

4 REPLIES 4
Haikuo
Onyx | Level 15

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

sophia_SAS
Obsidian | Level 7

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;

CTorres
Quartz | Level 8

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
Calcite | Level 5 avr
Calcite | Level 5

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

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1129 views
  • 0 likes
  • 4 in conversation