Hello SAS users, I have a question on how to get this right. I have a 10 digit NDC code in 3 formats as shown below. I need to add a '0' in specified places based on the format. Below is my code to solve this but I keep getting errors with the use of substring. I do know I can use scan to complete the process. But, I want to know if there is an efficient way to do this. NDC packagecode is same as NDC code. seq1endpos = find ( ndcpackagecode , "-") ;
seg1 = substr ( ndcpackagecode , 1 , seq1endpos - 1 ) ;
seq2endpos = find ( substr ( ndcpackagecode , seq1endpos + 1 , 10 ) , "-") ;
seg2 = substr ( ndcpackagecode , seq1endpos + 1 , seq2endpos - 1 ) ;
seg3 = substr ( ndcpackagecode , seq1endpos + seq2endpos + 1 , 2 ) ;
compressedcode = compress ( ndcpackagecode , "-" , "") ;
if length(trim(seg1)) = 5 then do ;
if length(trim(seg2)) = 4 and length(trim(seg3)) = 2 then do ;
ndccode = trim(seg1) || trim(seg2) || trim(seg3) ; ndcmod = 0 ;
end ;
if length(trim(seg2)) = 4 and length(trim(seg3)) = 1 then do ;
ndccode = trim(seg1) || trim(seg2) || '0' || trim(seg3) ; ndcmod = 1 ;
end ;
if length(trim(seg2)) = 3 and length(trim(seg3)) = 2 then do ;
ndccode = trim(seg1) || '0' || trim(seg2) || trim(seg3) ; ndcmod = 1 ;
end ;
if length(trim(seg2)) = 3 and length(trim(seg3)) = 1 then do ;
ndccode = trim(seg1) || '0' || trim(seg2) || '0' || trim(seg3) ; ndcmod = 1 ;
end ;
end ;
if length(trim(seg1)) = 4 then do ;
if length(trim(seg2)) = 4 and length(trim(seg3)) = 2 then do ;
ndccode = '0' || trim(seg1) || trim(seg2) || trim(seg3) ; ndcmod = 1 ;
end ;
if length(trim(seg2)) = 4 and length(trim(seg3)) = 1 then do ;
ndccode = '0' || trim(seg1) || trim(seg2) || '0' || trim(seg3) ; ndcmod = 1 ;
end ;
end ;
if length(ndccode) ne 11 then ndcbadlength = 1 ; else ndcbadlength = 0 ; NDC Conversion: 10-digit to 11-digit If 10-digit NDC format is: Then add a zero (0) in: Report NDC as: 4-4-2 9999-9999-99 1st position 09999-9999-99 09999999999 5-3-2 99999-999-99 6th position 99999-0999-99 99999099999 5-4-1 99999-9999-9 10th position 99999-9999-09 99999999909 Here is another example of how the end result should be: Can some one help. Thank you in advance.
... View more