Reading a file with multiple delimiters

Reply
New Contributor
Posts: 3

Reading a file with multiple delimiters

I am trying to read a file that uses the '|" and '^' as delimiters. The data is reading correctly until it gets to a certain point and then begins placing data in incorrect fields. Can anyone give any guidance on what I'm doing wrong? Below is the code I am using. Thank you in advance for any help you may be able to give.

data msh (keep=record Encoding_Characters Sending_Application Sending_Facility

        CLIA_Number CLIA Receiving_Application Receiving_Facility date ORU RO1

        ORU_RO1 Message_ControlID Processing_ID Version_ID Msg_Prof_Iden)

        pid (keep=record setid extid intid altid pt_name mm_name dob)

        obx (keep=record setid Value_Type obsid obssubid units refrng aflags

        prob nabntst orslsta dlobs udac obxdate);

    ;

    retain record;

      infile 'C:\test.txt' dsd dlm='|' dsd dlm='^'

        N=4;

    input type :$3. @;

    if type eq 'MSH' then

        do;

            input Encoding_Characters :$4. Sending_Application :$20.

                Sending_Facility :$30. CLIA_Number :$10. CLIA :$4.

                Receiving_Application :$8. Receiving_Facility :$5.

                /*/DATE FOTMAT NOT CORRECT NEEDS WORK /;*/

                DATE : $10. ORU :$3. RO1 :$3. ORU_RO1 :$7.

                Message_ControlID :$20. Processing_ID :$3. Version_ID : $8.

                Msg_Prof_Iden $8.;

            mshdate=input(substr(tempdt, 1, 8), yymmdd8.);

            record + 1;

            output msh;

        end;

    else if type eq 'PID' then

        do;

            input setid :$4.

(extid intid altid) (:$20.) (pt_name mm_name) (:$48.) tempdob :$26.;

            dob=input(substr(tempdob, 1, 8), yymmdd8.);

            output pid;

        end;

    else if type eq 'OBX' then

        do;

            input setid :$4. Value_Type :$2.

(obsid obssubid) (:$100.) units $:60. refrng :$10.

(aflags prob) (:$20.) nabntst :$2. orslsta :$1. dlobs :$26. udac :$20. unk :$1.

                tempdt :26.;

            obxdate=input(substr(tempdt, 1, 8), yymmdd8.);

            output obx;

        end;

    else

        delete;

    format mshdate dob obxdate yymmdd10.;

run;

proc print data=work.msh;

run;

proc print data=work.pid;

run;

proc print data=work.obx;

run;

Super User
Super User
Posts: 7,997

Re: Reading a file with multiple delimiters

Posted in reply to jkmorris85

Could be any number of issues, having '0a'x or '0d'x perhaps, returns, missing data, you use the option dsd, maybe you have one of those characters in the data etc.  Pretty difficult to tell from the code.  dlm can be shortened: dlm="|^".  You also appear to be mixing types, so you are stating split be delimiter, but also you have fixed widths for reading in.  Can't really say much more without the file itself.

New Contributor
Posts: 3

Re: Reading a file with multiple delimiters

Thank you so much. Below is a sample of the file I am trying to read.

MSH|^~\&|CERNER||PriorityHealth||||ORU^R01|Q479004375T431430612|P|2.3|

PID|||001677980||SMITH^CURTIS||19680219|M||||||||||929645156318|123456789|

OBX|1|341856649^HNAM_ORDERID|000002006326002362|648088^Basic Metabolic Panel|||20061122151600|||||||||1620^Hooker^Robert^L||||||20061122154733|||F|||||||||||20061122140000| OBX|1|NM|GLU^Glucose Lvl|59|mg/dL|65-99^65^99|L|||F|||20061122154733

I have tried combining the delimiters and it didn't work either. Thank you for the suggestion though.

New Contributor
Posts: 3

Re: Reading a file with multiple delimiters

Posted in reply to jkmorris85

Here is an example of the file I am trying to ready

MSH|^~\&|CERNER||PriorityHealth||||ORU^R01|Q479004375T431430612|P|2.3|

PID|||001677980||SMITH^CURTIS||19680219|M||||||||||929645156318|123456789|

PD1||||1234567890^LAST^FIRST^M^^^^^NPI| OBR|1|341856649^HNAM_ORDERID|000002006326002362|648088^Basic Metabolic Panel|||20061122151600|||||||||1620^Hooker^Robert^L||||||20061122154733|||F|||||||||||20061122140000|

OBX|1|NM|GLU^Glucose Lvl|59|mg/dL|65-99^65^99|L|||F|||20061122154733| - See more at: http://www.priorityhealth.com/provider/manual/office-mgmt/data-exchange/hl7/hl7-samples#sthash.zXDgp...

Super User
Posts: 11,343

Re: Reading a file with multiple delimiters

Posted in reply to jkmorris85

HL7 data transmittal is NOT conducive to simple data step input. From my brief exposure, each LINE may have a different format and you have to parse the first field to see how to read the remainder of that line.

A previous thread: https://communities.sas.com/message/15768 may help.

And this paper: http://www.lexjansen.com/nesug/nesug96/NESUG96057.pdf

Respected Advisor
Posts: 3,799

Re: Reading a file with multiple delimiters

Posted in reply to jkmorris85

You need to specify the delimiters as dlm='|^'

Using the option twice is not the correct syntax and SAS just uses the last one.

Ask a Question
Discussion stats
  • 5 replies
  • 438 views
  • 3 likes
  • 4 in conversation