DATA Step, Macro, Functions and more

How to get different titles for multiple tables using macros

Reply
Occasional Contributor
Posts: 13

How to get different titles for multiple tables using macros

Hi Experts,

 

i need help on how i can give different titles to multiple tables where most of my diffinations are in macros. A short program is below. i would like to also change the variable names to something else. There are as many as 10 tables for 5 countries with one for imports and the other for exports. the Arguments argn stands for the 5 countries and the  amx are for imports and exports. the rgn1fmt are the country format.

 

I need a code inside this program that can give the headings and rename my variables.

thanks.

 

%macro mk_table1(argn,amx);

data tmp;
set tbl1data;
by ctry_rgn descending mx;    /*All imports and exports*/

if mx=&amx;

if ctry_rgn=put(&argn,rgn1fmt.);


proc print data=tmp( drop=mx) noobs;
Format cal year. al comma12. ay negparen9.1 vl  comma12. vy negparen9.1
ol  comma12. oy negparen9.1 tl  comma12. ty negparen9.1;
run;

%mend mk_table1;

Super User
Posts: 19,815

Re: How to get different titles for multiple tables using macros

Sure, you can use the macro variables in your title as required.

 

If you need to apply a format, make sure to use %sysfunc() and PUTC/N as applicable.

 

Perhaps:

 

title "Imports from %sysfunc(putn(&argn, rgn1fmt))";
Occasional Contributor
Posts: 13

splitting a table into two and give different titles

Hi experts,

 

i need a program that can split a table into two. i have five tables and each one is to be split into two with different titles: imports and exports.  the argn is for imports and exports, ctry_rgn are the countries andrgn1fmt is the country format.

 

i already have the the codes that outputs the tables but i need a code in the program below that can split the tables into two with different titles. 

thanks.

 

%macro mk_table3(argn);

data tmp;
set tbl3data;
by ctry_rgn descending mx;

if ctry_rgn=put(&argn,rgn1fmt.);


run;

%mend mk_table3;

typical example is pasted below.

 

 

ca

od

mk

dy

mm

Jan

12

288

13

44

Feb

6

456

12

34

March

34

55

6

87

April

61

44

87

57

Jan

45

78

4

59

Feb

19

12

34

41

March

6

32

19

18

April

30

68

98

4

 

 

ca

od

mk

dy

mm

Jan

121

2881

13

44

Feb

63

4563

12

34

March

344

550

6

87

April

616

449

87

57

Jan

457

787

4

59

Feb

198

125

34

41

March

60

32

19

18

April

309

68

98

4

 

Super User
Posts: 19,815

Re: splitting a table into two and give different titles

Which part are you having problems with?

What do you have in terms of data, what do you want as output and what do you have so far in terms of code?

 

I made some assumptions with my initial answer, but since you reposted the question I assume it didn't answer your question. 

Super User
Super User
Posts: 7,961

Re: splitting a table into two and give different titles

You don;'t need to split datasets, nor use macro code.  There is in built Base SAS syntax for this tpe of task called by grou processing:

proc print data=tbl3data;
  by ctry_rgn;
  title "City is: #byval1";
run;

Its rarely a good idea to go splitting your data out, it will just make your code longer and more complicated.

Super User
Posts: 11,343

Re: How to get different titles for multiple tables using macros

Change what variables? For what use?

 

It may be that what you want for some of your variables are labels.

Your proc print with the variables al ay for instance. If you had

Label

   al = "Some description of AL"

   ay = "Some description of AY"

;

then you can display very detailed column headers in proc print with the LABEL option and by default most other procedures would display the labels.

 

Unless you are doing something to create entirely different documents or have more procedures than you show this could well be a case of using BY Group processing. You could then use #byvar and or #byval in a title.

 

 

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