07-06-2012 04:18 PM
there is a column A whoes format is $7, I want create a new column B with $10. the rule of create B is fill 'x' on the left side of A.
in column A,a row has value '12345'
I want to create B with value 'XXXXX12345' ($10.)
in column A,a row has value '1234567'
I want to create B with value 'XXX1234567'($10.)
07-06-2012 06:06 PM
You could use TRANSLATE (or even TRANWRD) function.
Use the RIGHT function to get the original value moved to the right then replace the spaces with XXX.
length b $ 10;
put (a b) (= $quote.);
Note that it is the LENGTH of the character variable that is important, not the FORMAT that is attached to it.
07-06-2012 07:03 PM
borrowed Astounding's code:
length b $10;
substr(b, 10-length(a)+1) = a;
07-09-2012 11:31 AM
hi ... PICTURE formats work with numeric variables
there have been several nice solutions posted that work with character data, here's another possibility ...
length b $10;
similar to Haikuo 's solution, but you should use a length statement when using the CAT functions given that the default length of the result is 200
if you really wanted a one statement solution that gives you a variable with a length of 10, you could get rid of the LENGTH statement and use a PUT function with the CATT result ...
b = put(catt(a,substr('xxxxxxxxxx',1,9-length(a))),$10.);