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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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