/***************************************************************************************************************** SAS file name: character_picture.sas File location: __________________________________________________________________________________________________________________ Purpose: To demonstrate how to write 'Picture Formats' for character variables in SAS. Author: Peter Clemmensen Creation Date: 01/08/2019 This program supports the blog post "Write Picture Formats For Character Variables in SAS" on SASnrd.com *****************************************************************************************************************/ /* Write function to mask last 4 characters */ proc fcmp outlib=work.functions.fun; function mask(string $) $; substr(string,max(1, length(string)-3),4)='XXXX'; return (string); endsub; run; /* Write format to mask last 4 characters */ options cmplib=work.functions; proc format; value $ mask (default=200) other=[mask()]; run; /* apply the format to Danish Social Secirity Numbers */ data test; cpr='2305842018'; output; cpr='1411701943'; output; cpr='1807994624'; output; cpr='0908454712'; output; cpr='0203047264'; output; format cpr $mask.; run; proc print data=test; run;