SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

NDC Format Conversion

Accepted Solution Solved
Reply
Highlighted
Occasional Contributor
Posts: 12
Accepted Solution

NDC Format Conversion

 

 

 

 

 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: 

Capture.PNG

Can some one help.

Thank you in advance.

 


Accepted Solutions
Solution
3 weeks ago
Super User
Posts: 19,167

Re: NDC Format Conversion

Robot surprised

 

To calculate the different segments, Use SCAN() to separate your components. 

Convert them to numerics using INPUT.

Use Zw to apply the format and recreate your new variable. 

Use CATX() to recreate your new variable.

 

 

The required structure is 5-4-2? Note that you never actually say that anywhere. If it's not, you can change the code.

 

Also, please post sample data as text, preferable in a data step but at least text. Otherwise it's hard to work with your data and it takes longer for you to get an answer.

 

delete_ndc.JPG

 

 

 

 

View solution in original post


All Replies
Solution
3 weeks ago
Super User
Posts: 19,167

Re: NDC Format Conversion

Robot surprised

 

To calculate the different segments, Use SCAN() to separate your components. 

Convert them to numerics using INPUT.

Use Zw to apply the format and recreate your new variable. 

Use CATX() to recreate your new variable.

 

 

The required structure is 5-4-2? Note that you never actually say that anywhere. If it's not, you can change the code.

 

Also, please post sample data as text, preferable in a data step but at least text. Otherwise it's hard to work with your data and it takes longer for you to get an answer.

 

delete_ndc.JPG

 

 

 

 

Occasional Contributor
Posts: 12

Re: NDC Format Conversion

Hi Reeza,

 

Thank you for your solution.

Sorry about the text issue.

 

The data posted was in 2 forms one as a table and another as a image. I posted the Image due to the formatting issue when as a text.

 

Thank you for the help. your solution worked.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 106 views
  • 0 likes
  • 2 in conversation