DATA Step, Macro, Functions and more

Outputting macro call output to a table and appending it with every macro call

Reply
Contributor
Posts: 20

Outputting macro call output to a table and appending it with every macro call

Hi Team,

               Here is what i need help into.

I have two macro definations

Macro1 and Macro2

and they have macro calls as

 

%macro1(a,b,c)

%macro1(a1,b1,c1)

%macro1(a2,b2,c2)

%macro2(p1,q1,r1,s1)

%macro2(p2,q2,r2,s2)

%macro2(p3,q3,r3,s3)

%macro2(p4,q4,r4,s4)

 

Both macro1 and macro2 have proc sql statement within them and output a 2 column 2 row output(1st row headers,which are differant for each macro call and second rows are numeric values.)

 

 

I want to append all results of macro calls(for both tables) into a  SAS dataset.Please help me on this.Thanks!

 

 

Super User
Posts: 17,829

Re: Outputting macro call output to a table and appending it with every macro call

Here are two options. 

 

Option 1: 

Make each macro generate an output table with a unique name and then appemd the results. Use a naming convention, such as a common prefix so that you can use either a colon or list to append all easily. 

 

Data results;

set result1-result10;*appends all tables in between result1, result2, etc;

run;

 

OR 

 

data want;

Set result:; *will append any table starting with the work result;

run; 

 

 

Option 2:

Or have each iteration of the macro append the results to a main result table. If you rerun a section you'll end up,with duplicate results so would need to manage that. 

For this option look at PROC appemd. 

Contributor
Posts: 20

Re: Outputting macro call output to a table and appending it with every macro call

Hi..thanks for reply,here is what i am trying to do now....i generated
tables with differant names....

So now i have table t1 with columns a,b
table t2 with colums c,d

I want to have table three with following column names and values:
t3 with column name X Y
a b
1 2
c d
2 1
so basically i want to have column headers and column values in t3 from
table t1 and t2.Please guide me on this.TIA

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Contributor
Posts: 20

Re: Outputting macro call output to a table and appending it with every macro call

Hi..thanks for reply,here is what i am trying to do now....i generated tables with differant names....

 
So now i have table t1 with columns a,b
                        table t2 with colums c,d
 
I want to have table three with following column names and values:
t3  with column name    X Y
                                      a  b
                                      1 2
                                       c d
                                       2 1
so basically i want to have column headers and column values in t3 from table t1 and t2.Please guide me on this.TIA
Super User
Posts: 17,829

Re: Outputting macro call output to a table and appending it with every macro call

Make them have the same name in your macro don't fix it after. 

Super User
Posts: 17,829

Re: Outputting macro call output to a table and appending it with every macro call

Make them have the same name in your macro don't fix it after. 

Ask a Question
Discussion stats
  • 5 replies
  • 164 views
  • 0 likes
  • 2 in conversation