BookmarkSubscribeRSS Feed
SASuserlot
Barite | Level 11

I want to create the dynamic titles using the same variable from data and some fixed Text strings.

In the following, I want to create the  'SchoolText' variable by creating the text string that looks like in the picture. My main requirement is to have proper alignment of Text with blank spaces depending on the  'School type' string length. (Maybe we can use the 'REPEAT' function to create the empty blank spaces based on the string length). 

In my example, New York city has three school information, and Maine has two school information. So 'School Text' should have the concatenation of strings accordingly).

Please ask question if its unclear or I am asking something doesn't make sense.

data title;
length School $15.;
school = 'Middle';
Median =  4.5;
SE	   =  5.34;
City = 'New York';

output;
school = 'High';
Median =  4.5;
SE	   =  5.34;
City = 'New York';

output;
school = 'Elementary';
Median =  .;
SE	   =  .;
City = 'New York';

output;
school = 'Middle';
Median =  4.5;
SE	   =  5.34;
City = 'Maine';

output;
school = 'High';
Median =  4.5;
SE	   =  .;
City = 'Maine';
output;
run;

options orientation = landscape errors = 2 missing = ' ' nofmterr ls = 175;

ods escapechar = '^';
ods noresults; 
ods listing close; 
%let path = Desktop;
ods rtf file = "&path.\title.rtf" style = Journal; 

	title1 j = l "City: #byval(city)";
	title2 j = l "#byval(SchoolText)";
proc print data = sashelp.class;
run;
Ods _all_ close;

this is how I am looking o achieve

SASuserlot_0-1687098699751.png

Thank you for your inputs

 

4 REPLIES 4
ballardw
Super User

To use #BYVAL and/or #BYVAR the procedure must use a BY statement.

 

Since you don't show any actual procedure output in that picture it is hard to tell where your "title" text is supposed to appear in relation to the proc print, or other procedure, output.

 

Please show an example of your "title" with actual procedural output. If you don't actually have any then you might look at Proc ODSTEXT to use your Title data set for display.

SASuserlot
Barite | Level 11

Thanks, @ballardw  is this the one you are asking about? I tried this way, but I had difficulty dynamically aligning the 'Schooltxt' variable in the title. Maybe I am doing something wrong in how to create blank spaces. Please let me know.

This is how I am getting; I am looking to alight the text 'School Performance SE score' under the 'School Performance Median Score.'

 

SASuserlot_0-1687113037670.png

 

 

data-title;
length School $15.;
school = 'Middle';
Median =  4.5;
SE	   =  5.34;
City = 'New York';

output;
school = 'High';
Median =  4.5;
SE	   =  5.34;
City = 'New York';

output;
school = 'Elementary';
Median =  .;
SE	   =  .;
City = 'New York';

output;
school = 'Middle';
Median =  4.5;
SE	   =  5.34;
City = 'Maine';

output;
school = 'High';
Median =  4.5;
SE	   =  .;
City = 'Maine';
output;
run;

proc sort data = title; by descending city ; run;
data check;
set title;
by descending city;
length schooltxt $5000;
retain schooltxt     ;

if first.city then schooltxt = '';
schooltxt = 'School Type = '||strip(school)||repeat(' ', 45-length(school))||'School Performance Median Score                   =  ('||put(Median , 5.1)||')^n'
							||' 					                      '||'School Performance SE Score						=  ('||put(SE , 6.2)||')';

run;

proc sort data = check out = check1;
	by city SCHOOLTXT;
run;
options orientation = landscape errors = 2 missing = ' ' nofmterr ls = 175 validvarname = upcase nofmterr nobyline;

ods escapechar = '^';
ods noresults; 
ods listing close; 
%let path = desktop;
ods rtf file = "&path.\title.rtf" style = Journal; 


 proc report data= check1;
 	title1 j = l "City: #byval(city)";
	title2 j = l "#byval(schooltxt)";
/*	title3 j = l "";*/


 by city schooltxt;
 column  ("^R/RTF'\brdrb\brdrs '" school median SE);
 define school     / display order = internal style(header) = [just=l] style(column) = [just=l vjust=t cellwidth=12.0% asis=on] "school	"  ;                                                     ;
	define median     / display order = internal style(header) = [just=l] style(column) = [just=l vjust=t cellwidth=6.0% asis=on]  "Median"   ;                                                      ;
	define se        / display order = internal style(header) = [just=c] style(column) = [just=c vjust=t cellwidth=3.0% asis=on]  "Standard error";   
run;
Ods _all_ close;
ballardw
Super User

@SASuserlot wrote:

Thanks, @ballardw  is this the one you are asking about? I tried this way, but I had difficulty dynamically aligning the 'Schooltxt' variable in the title.


 

Aligning  spaces is problematic in any destination that uses proportional fonts. Period. Spaces do not take the same space as most other characters and characters like . and i take up less space than m or w. So trying to align that way is just plane problematic.

 

You can try setting the font in the title statements to a monospace font, such as Courier or Courier New, to honor spacing set by spaces but that may look odd in relation to the rest of the document.

Since you are already inserting raw RTF codes then look up how to specify a column position and use that perhaps (too lazy do look up the codes myself as no real interest) to set the position for the "School Performance" text.

 

 

 

 

SASuserlot
Barite | Level 11

I can understand. Thank you for your feedback. 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1190 views
  • 0 likes
  • 2 in conversation