How to right-justify a left-justified field

Attached is LEFTJUSTIFIEDDATA.SPXwhich is an examplethat takes a 20 column field with a left justified number in it and right justifies it with commas. You can run either one of the two steps below independently to right justify or to insert commas.

There are two steps that need to be done.

  1. The number needs to be right justified. (Lines between *****)
  2. Commas need to be inserted where they are needed. (Lines between #####)

You can change the location of the variable Left to be the location you wish to change and then change the Repeat variables to match the numberof data positions in variable you have.

>PURGESAME~IN LEFTJUSTIFY^DAT,ASCII=80,-SHORTLINEWARN~OUT RIGHTJUSTIFY^DAT,ASCII,LENGTH=60,TRIM_BLANKS~DEFLeft:  [1.20$]Right: [21.20$]Comma: [41.20$]PROC=RightJustify: ''************************************************************Print_To_Data [(Right) 1.20] ">20s" [(Left) 1.20$] ''************************************************************** ''#############################################################Copy Comma = Right>Repeat $A=17,13,9,5; $B=16,12,8,4If [(Comma) $A.1^NB] ThenCopy [(Comma) 1.$B] = [(Comma) 2.$B]Modify [(Comma) $A.1$] = ","Endif>Endrepeat ''#############################################################Writecase}~EXCPROC=RightJustify~END

  • leftjustifieddata.spx
  • leftjustifieddata.dat