BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
peter_sjogarde
Fluorite | Level 6

Hi, 

 

I am trying to create titles in an ODS report with multiple tables. I would like one title above all tables and then one title for each table. The table are created by iteration. The title for each table is put in a variable. Output that i want:

 

Title 1 

 

Title 2

[table 1]

 

Title 3

[table 2]

 

But there seems to be something that I do not understand about how the titles are generated since I get very strange results. Some test code:

	* Open ods;
	ods listing close;
	ods graphics on;
	ods html file="&output_folder.\&cluster_label.\&cluster_label..html" headtext="<style>p,hr {display:none}</style>"
	style=Journal
	gpath="&output_folder.\&cluster_label.\graph"
	image_dpi=300;
	ods text='<div><h1 align="center">Cars</h1></div>';

			%macro car_var;
			data &var_name.; set sashelp.cars;
			if type = "&var_name."; 
			run;
			Title2 "<H2>&var_title.</H2>"; 
			proc print label
			data=&var_name.; 
			run;			

			%mend car_var;
			%Let var_name = Sports ; %Let var_title = Sports; %car_var
			%Let var_name = Sedan ; %Let var_title =  Sedan; %car_var

	ods html close;

Results:

<H2>Sedan</H2>

<div><h1 align="center">Cars</h1></div>

Obs Make Origin
1 Audi Europe
2 Audi Europe
3 Audi Europe
4 Audi Europe
5 BMW Europe
6 BMW Europe
7 BMW Europe
8 BMW Europe
9 Jaguar Europe
10 Jaguar Europe
11 Jaguar Europe
12 Jaguar Europe
13 Mercedes-Benz Europe
14 Mercedes-Benz Europe
15 Mercedes-Benz Europe
16 Mercedes-Benz Europe
17 Mercedes-Benz Europe
18 Porsche Europe
19 Porsche Europe
20 Porsche Europe
21 Porsche Europe
22 Porsche Europe
23 Porsche Europe

<H2>Sedan</H2>

Obs Make Origin
1 Audi Europe
2 Audi Europe
3 Audi Europe
4 Audi Europe
5 Audi Europe
6 Audi Europe
7 Audi Europe
8 Audi Europe
9 Audi Europe
10 Audi Europe
11 Audi Europe
12 Audi Europe
13 Audi Europe
14 BMW Europe
15 BMW Europe
16 BMW Europe
17 BMW Europe
18 BMW Europe
19 BMW Europe
20 BMW Europe
21 BMW Europe
22 BMW Europe
23 BMW Europe
24 BMW Europe
25 BMW Europe
26 BMW Europe
27 Jaguar Europe
28 Jaguar Europe
29 Jaguar Europe
30 Jaguar Europe
31 Jaguar Europe
32 Jaguar Europe
33 Jaguar Europe
34 Jaguar Europe
35 MINI Europe
36 MINI Europe
37 Mercedes-Benz Europe
38 Mercedes-Benz Europe
39 Mercedes-Benz Europe
40 Mercedes-Benz Europe
41 Mercedes-Benz Europe
42 Mercedes-Benz Europe
43 Mercedes-Benz Europe
44 Mercedes-Benz Europe
45 Mercedes-Benz Europe
46 Mercedes-Benz Europe
47 Mercedes-Benz Europe
48 Mercedes-Benz Europe
49 Mercedes-Benz Europe
50 Mercedes-Benz Europe
51 Mercedes-Benz Europe
52 Mercedes-Benz Europe
53 Saab Europe
54 Saab Europe
55 Saab Europe
56 Saab Europe
57 Saab Europe
58 Saab Europe
59 Volkswagen Europe
60 Volkswagen Europe
61 Volkswagen Europe
62 Volkswagen Europe
63 Volkswagen Europe
64 Volkswagen Europe
65 Volkswagen Europe
66 Volkswagen Europe
67 Volkswagen Europe
68 Volkswagen Europe
69 Volkswagen Europe
70 Volvo Europe
71 Volvo Europe
72 Volvo Europe
73 Volvo Europe
74 Volvo Europe
75 Volvo Europe
76 Volvo Europe
77 Volvo Europe
78 Volvo Europe

 

What am I doing wrong? Why is the ods text printed after title2? Why is title2 the same for both tables?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

From your code it appears you are trying to control the html appearance. Look at your htm with a text editor, not an html viewer. You will see that the title text has been put within html tags such that it will not render as headers.

 

I would suggest trying "bare" title text to see if it appears as needed. If you want to modify all of the titles then create a modified ODS template with different characteristics.

 

Also using proc report or tabulate a variable can have role of PAGE which may help.

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Whilst not a direct answer to your question, why not just do:

proc sort data=sashelp.cars out=cars;

  by type;

run;

proc report data=cars;

  columns make origin;

  by type;

  title "Cars";

  title2 "#byvar1";

run;

 

No need for all that code, the by syntax should suffice.

  

peter_sjogarde
Fluorite | Level 6

Thank you for your reply. I posted a simplified code since the real code is quite long and complicated. The reason I want to do it this way is that my code includes a transpose part which is done separetly for each variable. If done on all variables at ones, transpose will convert number formats.

 

orginial table looks something like this

country year var1 var2

1           2001   1   0.1

1           2002   2   0.2

1           2003   1   0.5

2           2001   1   0.1

2           2002   2   0.2

2           2003   1   0.5

 

The program makes one table per variable and presents it like this. The macro also makes it possible for me to exclude variables if I don't want them in a particular analysis. 

 

var1

country  2001   2002   2003

1                  1         2         1                   

2                  1         2         1       

 

var2

country  2001   2002   2003

1               0.1      0.2      0.5                  

2               0.1      0.2      0.5      

 

ballardw
Super User

From your code it appears you are trying to control the html appearance. Look at your htm with a text editor, not an html viewer. You will see that the title text has been put within html tags such that it will not render as headers.

 

I would suggest trying "bare" title text to see if it appears as needed. If you want to modify all of the titles then create a modified ODS template with different characteristics.

 

Also using proc report or tabulate a variable can have role of PAGE which may help.

peter_sjogarde
Fluorite | Level 6

Thank you! I suppressed the titles and used the ods text feature instead and that worked fine.

 

 

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
  • 1025 views
  • 1 like
  • 3 in conversation