LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (April 1999, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Mon, 19 Apr 1999 13:29:41 -0500
Reply-To:   Rob Rohrbough <rob@ROHRBOUGH-SYSTEMS.COM>
Sender:   "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:   Rob Rohrbough <rob@ROHRBOUGH-SYSTEMS.COM>
Comments:   To: "SAS-L List (SAS(r) Discussion) (E-mail)" <SAS-L@listserv.uga.edu>
Content-Type:   text/plain; charset="us-ascii"

As promised at the Coder's Corner, SAS-L Live from Miami Beach, here is my code to center a title in a DATA _NULL_ step:

%macro center (str1, str2, lgth); /* Center a string on length. */ &str2 = repeat(' ', max((&lgth - length(left(&str1)))/2, 0)) || left(&str1); %mend center;

The gentleman at the rear who asked if I had coded a C function was perceptive. My memory was not accurate - as you can see it is a macro. Not only that, it is not even called like a function although it could be recoded that way as a macro. I keep it in an include file. You could also cut and paste (not recommended). Here is an example of how I use it for reporting in a datastep starting with the log showing the program:

110 %macro center (str1, str2, lgth); /* Center a string on length. */ 111 &str2 = repeat(' ', max((&lgth - length(left(&str1)))/2, 0)) || left(&str1); 112 %mend center; 113 114 OPTIONS NONUMBER LS=85; 115 TITLE; 116 DATA _NULL_; 117 FILE PRINT; 118 TTLIN1 = 'First Title Line'; 119 %CENTER(TTLIN1, TTLOUT1, 65) 120 TTLIN2 = 'Second Title Line'; 121 %CENTER(TTLIN2, TTLOUT2, 85) 122 PAGENUM = 1; * Initialize page number - would be incremented in a real app; 123 PUT /// 'MYPROG ' TTLOUT1 $char65. ' ' pagenum 5.; 124 PUT TTLOUT2 $char85.; 125 RUN;

NOTE: 5 lines were written to file PRINT. NOTE: The DATA statement used 0.08 seconds.

Which produced the following output:

MYPROG First Title Line 1 Second Title Line

Hope this makes life a little easier for the person who asked the question,

Rob

Rob Rohrbough, Consultant Rohrbough Systems Design, Inc. 9215 Dorcas Street A SAS Institute Quality Partner Omaha, NE 68124-2039 rob@rohrbough-systems.com (402) 343-1493


Back to: Top of message | Previous page | Main SAS-L page