BookmarkSubscribeRSS Feed
Kinston
Calcite | Level 5

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;

5 REPLIES 5
Reeza
Super User

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))";
Kinston
Calcite | Level 5

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

 

Reeza
Super User

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. 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

ballardw
Super User

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.

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 5 replies
  • 1183 views
  • 0 likes
  • 4 in conversation