<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Reading NCPDP file in SAS Health and Life Sciences</title>
    <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Reading-NCPDP-file/m-p/2953#M241</link>
    <description>of course, this is a data loading problem rather than Health Care, but I think I can help.&lt;BR /&gt;
&lt;BR /&gt;
May I assume you have the data in the order of your input statements, and always separated by the delimiter you defined on your infile statement?&lt;BR /&gt;
&lt;BR /&gt;
Change your policy, from reading at specific positions with specific lengths, to the style which supports delimited data fields with varying positions.&lt;BR /&gt;
&lt;BR /&gt;
Infile statements support delimited separated data (DSD) with the infile option DSD. &lt;BR /&gt;
The input statement supports DSD by allowing input at the next "available" position (using no definitions like @NNN or @'string').&lt;BR /&gt;
Also input statements support DSD best, with no informat lengths defined on the input statement (because the implication of DSD is that we do not know the lengths and the SAS software will use the lengths we define on an input statement, to parse the line) &lt;BR /&gt;
&lt;BR /&gt;
What you need to do then, is predefine your variable lengths along with any non-default informats (especially for dates), before the input statement. Then just list your variables on the input statement, in input order. A bit like:&lt;BR /&gt;
data details ;&lt;BR /&gt;
  length TransactionReferenceNo $10 BinNumber $6 Version $2 TransactionCode $2 ProcessorControlNo $10 TransactionCount 3 ProviderIDQualifier $2 ProviderID $15 ServiceDate 6  CardholderID $8 CardholderFirstName $8 CardholderLastName $20  PlanID $8 RxSegment $2  RxReferenceNoQualifier $1  RxReferenceNo $7  ServiceIDQualifier $2 ServiceID $19 Quantity 8 FillNumber 3 DaysSupply 3 DAWCode $1  UCCharge 8 PrescriberIDQualifier $2 PrescriberID $15 ;&lt;BR /&gt;
   &lt;BR /&gt;
attrib ServiceDate  informat= mmddyy. format= date9. ;&lt;BR /&gt;
&lt;BR /&gt;
infile "e:\sasdata\test.mco.txt" dlm= '02'x  lrecl= 10000 ; * support lines wider than 256 ;&lt;BR /&gt;
     &lt;BR /&gt;
/* If you are really confident, you could use the short-form &lt;BR /&gt;
  input   TransactionReferenceNo  --  PrescriberID ;&lt;BR /&gt;
   otherwise, list all variables ................*/&lt;BR /&gt;
&lt;BR /&gt;
input TransactionReferenceNo  BinNumber Version  TransactionCode  ProcessorControlNo  TransactionCount  ProviderIDQualifier  ProviderID  ServiceDate   CardholderID  CardholderFirstName  CardholderLastName   PlanID  RxSegment   RxReferenceNoQualifier   RxReferenceNo   ServiceIDQualifier ServiceID  Quantity FillNumber  DaysSupply  DAWCode   UCCharge  PrescriberIDQualifier  PrescriberID ;&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Even if your data are spreading over more than one line, the approach above works, provided that the lines break between variables.&lt;BR /&gt;
&lt;BR /&gt;
Of course, I cannot see a sample of your data. If my assumptions are wrong, better help may be available, if you post a sample of your data (but please replace the '02'x delimiter with a "printable" character)&lt;BR /&gt;
&lt;BR /&gt;
Hope my description above is clear&lt;BR /&gt;
&lt;BR /&gt;
Good Luck&lt;BR /&gt;
&lt;BR /&gt;
Peter Crawford</description>
    <pubDate>Thu, 03 May 2007 10:29:54 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2007-05-03T10:29:54Z</dc:date>
    <item>
      <title>Reading NCPDP file</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Reading-NCPDP-file/m-p/2952#M240</link>
      <description>I'm not sure if anyone here has tried importing the NCPDP encounter file (?) but I'm having some problems. The file I'm working with comes from a tape system so records wrap from one line to the next in most cases. There are character strings to indicate the start of specific variables, and I have tried using @ '&lt;CHARACTER string=""&gt;' &lt;VARIABLE name=""&gt;  in my input statement to read these variables. For some reason it works fine on the first variable and then ignores all other variables for the record. &lt;BR /&gt;
&lt;BR /&gt;
I tried using the length = linelen trick to make sure that there wasn't an additional delimiter that was sending SAS to the next row, and the line length comes back as the correct length. Any ideas? The code I'm running is below.&lt;BR /&gt;
&lt;BR /&gt;
data detail ;&lt;BR /&gt;
infile "e:\sasdata\test.mco.txt" dlm='02'x truncover length=linelen;&lt;BR /&gt;
input &lt;BR /&gt;
	 @2 Segment $2. @;&lt;BR /&gt;
	if Segment = 'G1' then &lt;BR /&gt;
		input&lt;BR /&gt;
		 TransactionReferenceNo $10.&lt;BR /&gt;
		 BinNumber $6.&lt;BR /&gt;
		 Version $2.&lt;BR /&gt;
		 TransactionCode $2.&lt;BR /&gt;
		 ProcessorControlNo $10.&lt;BR /&gt;
		 TransactionCount 1.&lt;BR /&gt;
		 ProviderIDQualifier $2.&lt;BR /&gt;
		 ProviderID $15.&lt;BR /&gt;
		 ServiceDate 8.&lt;BR /&gt;
		 @'C2' CardholderID $ @;&lt;BR /&gt;
		input @'CC' CardholderFirstName $ @;&lt;BR /&gt;
		input @'CD' CardholderLastName $  @;&lt;BR /&gt;
		input PlanID $8.&lt;BR /&gt;
		 RxSegment $2.&lt;BR /&gt;
		 @'EM' RxReferenceNoQualifier $1. @;&lt;BR /&gt;
		input @'D2' RxReferenceNo	$7. @;&lt;BR /&gt;
		input @'E1' ServiceIDQualifier $2. @;&lt;BR /&gt;
		input @'D7' ServiceID $19. @;&lt;BR /&gt;
		input @'E7' Quantity 10. @;&lt;BR /&gt;
		input @'D3' FillNumber 2. @;&lt;BR /&gt;
		input @'D5' DaysSupply 3. @;&lt;BR /&gt;
		input @'D8' DAWCode $1. @;&lt;BR /&gt;
		input @'DQ' UCCharge 9. @;&lt;BR /&gt;
		input @'EZ' PrescriberIDQualifier $2. @;&lt;BR /&gt;
		input @'DB' PrescriberID $15.&lt;BR /&gt;
		;&lt;BR /&gt;
&lt;BR /&gt;
		varlen=linelen;&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;/VARIABLE&gt;&lt;/CHARACTER&gt;</description>
      <pubDate>Mon, 30 Apr 2007 18:54:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Reading-NCPDP-file/m-p/2952#M240</guid>
      <dc:creator>jasonDMNK</dc:creator>
      <dc:date>2007-04-30T18:54:34Z</dc:date>
    </item>
    <item>
      <title>Re: Reading NCPDP file</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Reading-NCPDP-file/m-p/2953#M241</link>
      <description>of course, this is a data loading problem rather than Health Care, but I think I can help.&lt;BR /&gt;
&lt;BR /&gt;
May I assume you have the data in the order of your input statements, and always separated by the delimiter you defined on your infile statement?&lt;BR /&gt;
&lt;BR /&gt;
Change your policy, from reading at specific positions with specific lengths, to the style which supports delimited data fields with varying positions.&lt;BR /&gt;
&lt;BR /&gt;
Infile statements support delimited separated data (DSD) with the infile option DSD. &lt;BR /&gt;
The input statement supports DSD by allowing input at the next "available" position (using no definitions like @NNN or @'string').&lt;BR /&gt;
Also input statements support DSD best, with no informat lengths defined on the input statement (because the implication of DSD is that we do not know the lengths and the SAS software will use the lengths we define on an input statement, to parse the line) &lt;BR /&gt;
&lt;BR /&gt;
What you need to do then, is predefine your variable lengths along with any non-default informats (especially for dates), before the input statement. Then just list your variables on the input statement, in input order. A bit like:&lt;BR /&gt;
data details ;&lt;BR /&gt;
  length TransactionReferenceNo $10 BinNumber $6 Version $2 TransactionCode $2 ProcessorControlNo $10 TransactionCount 3 ProviderIDQualifier $2 ProviderID $15 ServiceDate 6  CardholderID $8 CardholderFirstName $8 CardholderLastName $20  PlanID $8 RxSegment $2  RxReferenceNoQualifier $1  RxReferenceNo $7  ServiceIDQualifier $2 ServiceID $19 Quantity 8 FillNumber 3 DaysSupply 3 DAWCode $1  UCCharge 8 PrescriberIDQualifier $2 PrescriberID $15 ;&lt;BR /&gt;
   &lt;BR /&gt;
attrib ServiceDate  informat= mmddyy. format= date9. ;&lt;BR /&gt;
&lt;BR /&gt;
infile "e:\sasdata\test.mco.txt" dlm= '02'x  lrecl= 10000 ; * support lines wider than 256 ;&lt;BR /&gt;
     &lt;BR /&gt;
/* If you are really confident, you could use the short-form &lt;BR /&gt;
  input   TransactionReferenceNo  --  PrescriberID ;&lt;BR /&gt;
   otherwise, list all variables ................*/&lt;BR /&gt;
&lt;BR /&gt;
input TransactionReferenceNo  BinNumber Version  TransactionCode  ProcessorControlNo  TransactionCount  ProviderIDQualifier  ProviderID  ServiceDate   CardholderID  CardholderFirstName  CardholderLastName   PlanID  RxSegment   RxReferenceNoQualifier   RxReferenceNo   ServiceIDQualifier ServiceID  Quantity FillNumber  DaysSupply  DAWCode   UCCharge  PrescriberIDQualifier  PrescriberID ;&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Even if your data are spreading over more than one line, the approach above works, provided that the lines break between variables.&lt;BR /&gt;
&lt;BR /&gt;
Of course, I cannot see a sample of your data. If my assumptions are wrong, better help may be available, if you post a sample of your data (but please replace the '02'x delimiter with a "printable" character)&lt;BR /&gt;
&lt;BR /&gt;
Hope my description above is clear&lt;BR /&gt;
&lt;BR /&gt;
Good Luck&lt;BR /&gt;
&lt;BR /&gt;
Peter Crawford</description>
      <pubDate>Thu, 03 May 2007 10:29:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Reading-NCPDP-file/m-p/2953#M241</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-05-03T10:29:54Z</dc:date>
    </item>
  </channel>
</rss>

