LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (October 2002, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 4 Oct 2002 11:23:07 -0400
Reply-To:     Sigurd Hermansen <HERMANS1@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Sigurd Hermansen <HERMANS1@WESTAT.COM>
Subject:      Re: Better way to code this???
Comments: To: Jeff Morison <jmt_mtf@YAHOO.COM>
Content-Type: text/plain; charset="iso-8859-1"

>Hi Folks:

> Is there any better way to code this?. >I am inheriting this code from other programmer, just >want to improve it.

>TIA, >Jeff

>if current_first_name = 'ABBE' then stdfname='AB'; >if current_first_name = 'ABI' then stdfname='AB'; >if current_first_name = 'ABDU' then stdfname='ABD'; >if current_first_name = 'ABDOOL' then stdfname='ABDL'; >if current_first_name = 'ABDUL' then stdfname='ABDL'; <snip almost endless sequence of program statements>

To be candid about it, you could hardly do worse. It appears to me that the other programmer generated the program statements automatically. If so, it would make some sense to regenerate the program after you update the tables the other programmer may have used to generate this program.

It would make better sense within the SAS System to generate a FORMAT, as others have suggested. I copied and pasted your excessively long message to a text file, and cut out everything but the repetitive statements. This program extracts the critical information and creates a format:

libname lib "c:\windows\temp"; filename toFmt "c:\windows\temp\betterWay.txt";

data lib.fmt; length start $ 15 label $ 8 ; infile toFmt dlm=" '" end=eof; fmtName="$FNSNDX"; do until(eof); input @"=" start $ @"=" label $ @@;

start=trim(compress(start,"0123456789abcdefghijklmnopqrstuvwxyz;'_"));

label=trim(compress(label,"0123456789abcdefghijklmnopqrstuvwxyz;'_")); output; end; stop; run; proc sql; create table lib.fmt as select distinct * from lib.fmt ; create table lib.test as select * from lib.fmt group by start having count(*)>1 ; create table lib.fmt as select * from lib.fmt group by start having label=max(label) ; quit;

proc format cntlin=lib.fmt; run;

Note that the program includes data quality checks. The program that you inherited has one duplicated statement and two statements that map the same value to two different labels. PROC FORMAT will not allow this for good reason, and it reports the errors in the expression of the mapping function.

Once you have the FORMAT defined, a program such as

data _null_; name='ABBE'; lbl=put(name,$FNSNDX.); put lbl; run;

prints the label associated with a name string.

Sig


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