SAS 9.4M5 EG 7.14 x64 Data Step used for testing and debugging: data _null_; length szName $ 12; szCourse = 'PHIL '; szNmbr1 = '112 '; szNmbr2 = '112LAB'; intLen = lengthn(cats(szCourse, szNmbr1)); intInsert = 11 - intLen; szName = cat(trim(szCourse), repeat(' ', intInsert), trim(szNmbr1)); intNameLen = lengthn(szName); intNameLen = length(szName); intLen = lengthn(cats(szCourse, szNmbr2)); intInsert = 11 - intLen; szName = cat(trim(szCourse), repeat(' ', intInsert), trim(szNmbr2)); intNameLen = lengthn(szName); intNameLen = length(szName); run; The data step works as expected; it concatenates the course and number, separated by a derived number of spaces to produce a left-aligned course name, x spaces, right-aligned course number that is always 12 total character long. This comports with the SAS documentation for the repeat() function as an n+1 result. When I move the core code into a proc FCMP function, repeat() behaves differently for some reason - it produces an n+2 result, requiring me to adjust my math. PROC FCMP OUTLIB=&IE_Functions; FUNCTION Build_Course_ID(szSubj $, szNumber $) $ 12; length szName $ 12; intInsert = 10 - lengthn(cats(szSubj, szNumber)); szName = cat(trim(szSubj), repeat(' ', intInsert), trim(szNumber)); return(szName); ENDSUB; RUN;
... View more