Please post test data in the form of a datastep:
https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712
And what you want to see out at the end, otherwise we are guessing on both. You say you have 20 columns, but never mention what these are, how they are used or any relevance to the code. You state using SQL, but do not give any reasons for this - SQL is built to run on normalised data - i.e. few columns, lots of observations - and as such isn't a good tool for lots of columns. Datastep and an array would be easier - obviously still guessing as no information provided. Its likely that you could just format the value with a custom format and avoid all conditional programming at all.
... View more