<?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: How to read in HL7 data into sas in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64015#M13918</link>
    <description>Cynthia,&lt;BR /&gt;
&lt;BR /&gt;
I did exactly the same way that you said here above. I used @ to retain the data to be read after each segment read in. By somereason, by program works good for the data file which is saved as .txt. But is not working for .raw file, which is what we use internally to read in the raw data that comes from source.&lt;BR /&gt;
&lt;BR /&gt;
Also '^' are internal separators in the variables. For ex: in case of names, we will be again separting First name, Last name middle intial etc.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
thanks,

Message was edited by: Sasbase</description>
    <pubDate>Tue, 02 Dec 2008 20:00:18 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-12-02T20:00:18Z</dc:date>
    <item>
      <title>How to read in HL7 data into sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64010#M13913</link>
      <description>I have data coming in HL7 pipe delimited text file. How to read this in SAS data step using infile statement.&lt;BR /&gt;
&lt;BR /&gt;
Though I am having more than 1 record, my infile statement is giving me as 1 record and I am not getting data dump.&lt;BR /&gt;
&lt;BR /&gt;
thanks,</description>
      <pubDate>Tue, 02 Dec 2008 14:31:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64010#M13913</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-12-02T14:31:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in HL7 data into sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64011#M13914</link>
      <description>Hi:&lt;BR /&gt;
  I remembered reading about HL7 when I was doing some research on XML and CDISC. It looks like your solution may be to use the SAS XML Libname Engine if the file is XML-based. If the data file is NOT XML based, then you should be able to use standard INFILE syntax, possible with DLM= option to parse the data and read it into SAS datasets.&lt;BR /&gt;
                     &lt;BR /&gt;
  It would help to see what your data looks like. If you cannot post it because it is lab or pathology data and you don't have any dummy data that you could post and you need help reading it, then you should consider contacting SAS Technical Support.&lt;BR /&gt;
                                 &lt;BR /&gt;
  Here are some misc links I had from previous research.&lt;BR /&gt;
&lt;A href="http://www.listserv.uga.edu/cgi-bin/wa?A2=ind0506d&amp;amp;L=sas-l&amp;amp;P=62837" target="_blank"&gt;http://www.listserv.uga.edu/cgi-bin/wa?A2=ind0506d&amp;amp;L=sas-l&amp;amp;P=62837&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://www.lexjansen.com/pharmasug/2004/sasinstitute/sas3.pdf" target="_blank"&gt;http://www.lexjansen.com/pharmasug/2004/sasinstitute/sas3.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://www.xml4pharma.com/HL7-XML/HL7-XML_for_CDISC_Standards.pdf" target="_blank"&gt;http://www.xml4pharma.com/HL7-XML/HL7-XML_for_CDISC_Standards.pdf&lt;/A&gt;&lt;BR /&gt;
           &lt;BR /&gt;
cynthia</description>
      <pubDate>Tue, 02 Dec 2008 15:36:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64011#M13914</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-12-02T15:36:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in HL7 data into sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64012#M13915</link>
      <description>Hey Cynthia,&lt;BR /&gt;
&lt;BR /&gt;
I tried reading the data using the infile statement and using pipe as DLM, Record Format as Fixed and outputting each of the segment data into different datasets.&lt;BR /&gt;
&lt;BR /&gt;
It is not reading in data  properly and showing as only 1 record. Since our data is usual text file, I may not need XML etc.&lt;BR /&gt;
&lt;BR /&gt;
Here is sample data:&lt;BR /&gt;
&lt;BR /&gt;
seg1|^~\&amp;amp;|LMS|LMS|sgx|igx|20080101135444||||20080101135444&lt;BR /&gt;
seg2|^~\&amp;amp;|LMS|LMS|sgx|sgx|||ORU^R01|200810241354441|P|2.3&lt;BR /&gt;
seg3|R01|20080101135444540&lt;BR /&gt;
seg4|1|123456789|66273||Linda^Chambers^L||1968-01-21|F|||23 Sargent Dr^^The Woodlands^OH^12345^^H||2031239876||||||123456789&lt;BR /&gt;
seg2|^~\&amp;amp;|LMS|LMS|sgx|sgx|||ORU^R01|200810241354442|P|2.3&lt;BR /&gt;
seg3|R01|20081024135444556&lt;BR /&gt;
seg4|1|472663806|138710||Dough^Thomas^M||1947-01-27|M|||2345 Sea View Dr^^Sugar Land^MA^77789^^H||7815468998||||||5645671930&lt;BR /&gt;
&lt;BR /&gt;
And these seg* are repeated in turn. My program should writeout each segment info into a different dataset.&lt;BR /&gt;
&lt;BR /&gt;
Any insight with this kind of data is more appreciated !!&lt;BR /&gt;
&lt;BR /&gt;
thanks,

Message was edited by: Sasbase</description>
      <pubDate>Tue, 02 Dec 2008 17:44:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64012#M13915</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-12-02T17:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in HL7 data into sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64013#M13916</link>
      <description>If you have delimited files, you are looking at some detailed data step programming.  There are several versions of the HL-7 standard and they have some differences in formatting so be sure the documentation matches the data.&lt;BR /&gt;
&lt;BR /&gt;
As far as seeing one long data record, that may be a source data compatibility problem.  Some operating systems do not separate "records" by a CR or a CR+LF-pair delimiter.  You may need to work closer on the format with your data provider on more detailed formats.</description>
      <pubDate>Tue, 02 Dec 2008 19:06:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64013#M13916</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2008-12-02T19:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in HL7 data into sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64014#M13917</link>
      <description>Hi: I have a few questions:&lt;BR /&gt;
what does  the ^~\&amp;amp; represent? what does the single ^ represent (as in ORU^R01 in your line 2 of data)? Do you have some kind of data layout that tells you what you might find between each set of delimiters? You'll have to use that documentation in order to build your INPUT statements.&lt;BR /&gt;
   &lt;BR /&gt;
Also, generally record format of fixed only applies to mainframe files -- where do these data files live? Usually Windows and Unix files are Variable length. And, as Doc says, you may have CR or CR+LF issues with the system that's sending you the data. You may need to investigate this.&lt;BR /&gt;
&lt;BR /&gt;
Do you want all the SEG1 obs into a dataset; all the SEG2 into a dataset, all the SEG3 into a dataset???&lt;BR /&gt;
OR&lt;BR /&gt;
You want SEG1 through SEG4 in one dataset and SEG2-SEG4 in a second dataset??&lt;BR /&gt;
What is a SEG*?? Is each number a separate observation or is a group of seg numbers one observation?&lt;BR /&gt;
&lt;BR /&gt;
Looking at this, you'd probably be beyond a simple INFILE/INPUT. It looks like each SEG data line has a different number of variables on it. Which points to a trailing @ to hold the line, while your program decides which SEG it has. Something along the lines of this code snippet (not tested):&lt;BR /&gt;
[pre]&lt;BR /&gt;
input @1 segind $4. @;  &amp;lt;---the trailing @ holds the input buffer for a further read;&lt;BR /&gt;
if segind = 'seg1' then do;&lt;BR /&gt;
  input funnychars $ var1 $ var2 $var3 $;&lt;BR /&gt;
  output work.seg1;&lt;BR /&gt;
end;&lt;BR /&gt;
else if segind = 'seg2' then do;&lt;BR /&gt;
  input funnychars $  x2 x3 x4 x5;&lt;BR /&gt;
  output work.seg2;&lt;BR /&gt;
end;&lt;BR /&gt;
else if segind = 'seg3' then do;&lt;BR /&gt;
  input rnum $ bignum;&lt;BR /&gt;
  output work.seg3;&lt;BR /&gt;
end;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
But you get the idea. The '@' allows you to read something from the input buffer (like the seg #) and then decide which INPUT statement to use. If you needed to keep a group of SEG #s together, then you'd have to decide which variables belonged together and probably use RETAIN in order to assemble one observation from multiple SEG # data lines. The example snippet above would create one data set for every SEG #....so your DATA statement would look like:&lt;BR /&gt;
[pre]&lt;BR /&gt;
  data seg1(keep=....)&lt;BR /&gt;
       seg2(keep=...)&lt;BR /&gt;
       seg3(keep=...);&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
                  &lt;BR /&gt;
cynthia</description>
      <pubDate>Tue, 02 Dec 2008 19:39:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64014#M13917</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-12-02T19:39:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in HL7 data into sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64015#M13918</link>
      <description>Cynthia,&lt;BR /&gt;
&lt;BR /&gt;
I did exactly the same way that you said here above. I used @ to retain the data to be read after each segment read in. By somereason, by program works good for the data file which is saved as .txt. But is not working for .raw file, which is what we use internally to read in the raw data that comes from source.&lt;BR /&gt;
&lt;BR /&gt;
Also '^' are internal separators in the variables. For ex: in case of names, we will be again separting First name, Last name middle intial etc.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
thanks,

Message was edited by: Sasbase</description>
      <pubDate>Tue, 02 Dec 2008 20:00:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64015#M13918</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-12-02T20:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in HL7 data into sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64016#M13919</link>
      <description>SASbase,&lt;BR /&gt;
&lt;BR /&gt;
Cynthia just gave you the shell of a program to read the data.  It's what I did some years ago when I had to work with HL7 data.  Once you've determined the record type (the seg #), you can use the usual SAS input statements to get the data in.  As I recall, the person identifier is on one of the early seg's, so you'll need a RETAIN to save that for each output record.&lt;BR /&gt;
&lt;BR /&gt;
Doc Muhlbaier&lt;BR /&gt;
Duke</description>
      <pubDate>Tue, 02 Dec 2008 20:05:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64016#M13919</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2008-12-02T20:05:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in HL7 data into sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64017#M13920</link>
      <description>Hi:&lt;BR /&gt;
  If the trailing @ is working correctly for an ASCII text file, but not for your "raw" file, then you need to investigate the difference in how the 2 files are created. If the "raw" file has carriage return/line feed issues, then you may need to get the creators of the raw file to make sure that the standard end of record/carriage return/line feed characters are put into the file.&lt;BR /&gt;
&lt;BR /&gt;
  BTW, this may seem like a fine point, but as an instructor, I have to make sure you understand that @ is not "retaining" data. @ is freezing the input pointer in the input buffer so you can go back and reread the input buffer with another INPUT statement -- another way to think about it is to say that @ is "holding" the input buffer open at the end of the INPUT statement. Usually you get one "read" of the input data file per INPUT statement. This is not what you want to do. You want your program to have several INPUT statements to read the same data line without having each INPUT statement cause a new data line to be read into the input buffer.&lt;BR /&gt;
&lt;BR /&gt;
There's a difference between holding the input buffer for a subsequent INPUT statement and using the RETAIN statement to retain the value of a variable across executions of an INPUT or SET statement. If you continue to have issues reading the file, then you should consider contacting SAS Tech Support for more detailed help.&lt;BR /&gt;
&lt;BR /&gt;
cynthia</description>
      <pubDate>Tue, 02 Dec 2008 22:37:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64017#M13920</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-12-02T22:37:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in HL7 data into sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64018#M13921</link>
      <description>Cynthia,&lt;BR /&gt;
&lt;BR /&gt;
Our problem to read in the raw data was resolved by keeping DOS end of Line character in the file.&lt;BR /&gt;
&lt;BR /&gt;
Now my question is how to output to a file a few variables from each segment?&lt;BR /&gt;
&lt;BR /&gt;
I have tried using retain and it is outputting as separate variables. But I need them to include those particular variables in one line separated by a comma or pipe.&lt;BR /&gt;
&lt;BR /&gt;
thanks,&lt;BR /&gt;
sasbase</description>
      <pubDate>Mon, 29 Dec 2008 19:58:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64018#M13921</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-12-29T19:58:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in HL7 data into sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64019#M13922</link>
      <description>Hi:&lt;BR /&gt;
  Once you have your data into a SAS dataset, then your choices are to use ODS to create a comma separated file or to use a DATA step program (with FILE and PUT statements) to write a "flat file" from the SAS dataset (without using ODS)&lt;BR /&gt;
[pre]&lt;BR /&gt;
&lt;BR /&gt;
**1a) Use ODS CSV;&lt;BR /&gt;
ods csv file='classout1a.csv';&lt;BR /&gt;
                 &lt;BR /&gt;
proc print data=sashelp.class noobs;&lt;BR /&gt;
var name age sex height;&lt;BR /&gt;
run;&lt;BR /&gt;
        &lt;BR /&gt;
ods csv close;&lt;BR /&gt;
&lt;BR /&gt;
                &lt;BR /&gt;
**2) Use DATA _NULL_;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  set sashelp.class;&lt;BR /&gt;
  p = '|';&lt;BR /&gt;
  file 'c:\temp\class_pipe.txt';&lt;BR /&gt;
  if _n_ = 1 then do;&lt;BR /&gt;
     put 'Name|Age|Sex|Height';&lt;BR /&gt;
  end;&lt;BR /&gt;
  put name p age p sex p height;&lt;BR /&gt;
run;&lt;BR /&gt;
               &lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                                &lt;BR /&gt;
You could also use PROC EXPORT and/or get an update to the CSV tagset that allows you to specify the delimiter that you want to use when you create your output file.&lt;BR /&gt;
&lt;BR /&gt;
RETAIN will only be useful when you want to retain a variable value across multiple iterations of the data step. As, for example, you have some material on a SEG1 input record (like a name) and you want to retain that name value across all iterations of the "seg" input lines for that name. So I don't understand how RETAIN is doing any outputting for you. &lt;BR /&gt;
&lt;BR /&gt;
It almost sounds like you want to read in data using INFILE/INPUT and then write it out again using FILE/PUT without ever having a SAS dataset for any other kind of analysis. If this is what you need to do, then you may want to work with Tech Support, as they can look at all your code and your data and help you with the most appropriate techniques.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Mon, 29 Dec 2008 21:48:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64019#M13922</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-12-29T21:48:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in HL7 data into sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64020#M13923</link>
      <description>Cynthia,&lt;BR /&gt;
&lt;BR /&gt;
Please see this data:&lt;BR /&gt;
&lt;BR /&gt;
MSH|^~\&amp;amp;||.|||199908180016||ADT^A04|ADT.1.1698593|P|2.5&lt;BR /&gt;
PID|1||000395122||LEVERKUHN^ADRIAN^C^^^||19880517180606|M|^^^^^||6 66TH AVE NE^^WEIMAR^DL^98052||(157)983-3296|||S||12354768|87654321&lt;BR /&gt;
NK1|1|TALLIS^THOMAS^C|GRANDFATHER|12914 SPEM ST^^ALIUM^IN^98052|(157)883-6176&lt;BR /&gt;
NK1|2|WEBERN^ANTON|SON|12 STRASSE MUSIK^^VIENNA^AUS^11212|(123)456-7890&lt;BR /&gt;
PV1|1|E|EMG-W^^|1||||||||||ER||||ER||H|||||||||||||||||||OVL||REG|||199908180015&lt;BR /&gt;
GT1|1||SMITH^JAMES^M||12914 164TH AVE NE^^RICHMOND^ON^98052|(157)883-6176|||||F|535-52-9776||||WEISS JENSON|.^^WELLINGTON^ON^.|(206)340-9577 &lt;BR /&gt;
IN1|1|PRE2|001|LIFE PRUDENT BUYER|PO BOX 23523^WELLINGTON^ON^98111|||19601||||||||THOMAS^JAMES^M|F|||||||||||||||||||ZKA535529776&lt;BR /&gt;
ZLM|1|&lt;BR /&gt;
&lt;BR /&gt;
I have my data as said given above and I wanter to take few of the variables from each segment like PID, PV1IN1 etc and write it out to a file, how to do in SAS.&lt;BR /&gt;
&lt;BR /&gt;
Data is again repeated PID to IN1 segments and Data in these segments from PID to IN1 represent info of one person and make a complete record of that person.&lt;BR /&gt;
&lt;BR /&gt;
Actually the way I am doing is: Read in the data using the first 3 bytes and write to different datasets and also write to a common dataset and the data from common dataset to a file usinf File Out statement. Data is not writing out properly and is all spread over. How this issue can be resolved?&lt;BR /&gt;
&lt;BR /&gt;
thanks a lot in advance,&lt;BR /&gt;
sasbase9</description>
      <pubDate>Sat, 10 Jan 2009 19:38:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64020#M13923</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-01-10T19:38:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in HL7 data into sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64021#M13924</link>
      <description>Hi:&lt;BR /&gt;
  As I explained earlier -- the code that I posted was for the scenario where you WANTED to have each record type or "seg" dataline in a different data set. &lt;BR /&gt;
If you need to have all the information for one person/employee/patient assembled together from multiple data lines into 1 observation, then the technique &lt;BR /&gt;
I illustrated would NOT be the program you wanted.&lt;BR /&gt;
 &lt;BR /&gt;
  Let's start with some simpler data. I have this data in a file called FAMDATA.TXT:&lt;BR /&gt;
[pre]&lt;BR /&gt;
e1,"Doug Jones",M,35&lt;BR /&gt;
s1,"Mandy Jones",F,35&lt;BR /&gt;
c1,"son",6,"David",M&lt;BR /&gt;
c2,"daughter",3,"Melissa",F&lt;BR /&gt;
a1,"1234 Some St.","Dallas","TX",75020&lt;BR /&gt;
e1,"Anne Austin",F,37&lt;BR /&gt;
s1,"Jack Austin",M,37&lt;BR /&gt;
c1,"step-daughter",10,"Andrea",F&lt;BR /&gt;
c2,"daughter",8,"Jeanine",F&lt;BR /&gt;
e1,"Bud Hollis",M,37&lt;BR /&gt;
s1,"Suzie Queue",F,36&lt;BR /&gt;
c1,"step-son",10,"Sam",M&lt;BR /&gt;
a1,"3456 Cricket Lane","Dallas","TX",75021&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Note that I have 3 families -- the Jones, Austin and Hollis families. In this data, the 'e1' data line is the employee record; the 's1' dataline is the spouse record; &lt;BR /&gt;
the 'c1', 'c2' lines are for the child records (in my data, people can have 0, 1 or 2 children); finally, the 'a1' data line holds the street, city, state and zip code.&lt;BR /&gt;
                             &lt;BR /&gt;
So, I am going to need a different INPUT statement for each record indicator, and I am not going to have a whole family assembled until I either read &lt;BR /&gt;
the 'a1' record for the family or I read the 'e1' record (I know that Mr. Jones family observation is ready to output when I read the Austin 'e1' record.) In my &lt;BR /&gt;
data, it is possible to have an employee in the file without an address (as with the Austin family), so I cannot use the output on 'a1' logic in my program.&lt;BR /&gt;
 &lt;BR /&gt;
From these individual records, I want to assemble a single observation for each employee in a SAS dataset. The assembled record will have these variables:&lt;BR /&gt;
&lt;B&gt;employee emp_gender emp_age  (from e1) &lt;BR /&gt;
spouse sp_gender sp_age (from s1)&lt;BR /&gt;
child1 gender1 rel1 age1 (from c1)&lt;BR /&gt;
child2 gender2 rel2  age2 (from c2) street city state zip (from a1) &lt;/B&gt; &lt;BR /&gt;
    &lt;BR /&gt;
If any of the record indicators are not found (no child 2 or no address or no spouse), then the variables need to be set to missing. So, for the above &lt;BR /&gt;
FAMDATA.TXT file, I want to assemble this final SAS dataset:&lt;BR /&gt;
[pre]&lt;BR /&gt;
use trailing @ and conditional output to assemble the whole obs from multiple input lines&lt;BR /&gt;
                                     &lt;BR /&gt;
                 emp_&lt;BR /&gt;
Obs  employee   gender   emp_age     spouse      sp_gender   sp_age   child1   gender1   rel1            age1   child2    gender2     rel2     age2        street          city    state    zip&lt;BR /&gt;
                       &lt;BR /&gt;
 1  Doug Jones    M         35     Mandy Jones       F         35     David       M      son               6    Melissa      F      daughter     3    1234 Some St.       Dallas    TX     75020&lt;BR /&gt;
 2  Anne Austin   F         37     Jack Austin       M         37     Andrea      F      step-daughter    10    Jeanine      F      daughter     8&lt;BR /&gt;
 3  Bud Hollis    M         37     Suzie Queue       F         36     Sam         M      step-son         10                                     .    3456 Cricket Lane   Dallas    TX     75021&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                                                                                           &lt;BR /&gt;
In order for this final observation to be assembled, I needed to explicitly RETAIN the employee and spouse and child information every time I read a specific &lt;BR /&gt;
record indicator in order to make sure that I had all the information available when I wrote out the final "assembled" observation.&lt;BR /&gt;
  &lt;BR /&gt;
Think of it like this. SAS can only handle one raw data line at a time. So your program has one chance to "catch and save" the information as you are &lt;BR /&gt;
holding the record in the input buffer. The INPUT statement does the reading from the buffer. That's the "catching" or reading the information from the raw &lt;BR /&gt;
data line. But the RETAIN statement does the "saving" of the information until you're ready to do the OUTPUT.&lt;BR /&gt;
           &lt;BR /&gt;
Usually, with a simpler set of raw data, you have one OUTPUT (implied) at the end of the DATA step program for every INPUT statement. But in the program &lt;BR /&gt;
that's needed to read the FAMDATA.TXT data, I only have one OUTPUT statment (explicit) for every group of INPUT statements. And, then I have one final &lt;BR /&gt;
OUTPUT statement for when I read the end of the raw data file.&lt;BR /&gt;
         &lt;BR /&gt;
The SAS program that read FAMDATA.TXT and produced the above output is shown below. You may need to really study how my program is working &lt;BR /&gt;
before you can change your program successfully. I suggest you start with some very SIMPLE data. Try the program with and without RETAIN. &lt;BR /&gt;
Experiment with having the OUTPUT statement in different places and see what happens. Until you understand the DATA step and how SAS processes&lt;BR /&gt;
 raw data and how the RETAIN statement works, you will have problems writing a program to read your HL7 data successfully. You can always contact &lt;BR /&gt;
Tech Support for more one-on-one help with your specific data and your specific program.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
data allrec&lt;BR /&gt;
     (keep=employee emp_gender emp_age spouse sp_gender sp_age&lt;BR /&gt;
           child1 gender1 rel1 age1 &lt;BR /&gt;
		   child2 gender2 rel2 age2 &lt;BR /&gt;
           street city state zip);&lt;BR /&gt;
length employee $20 emp_gender $1 emp_age 8&lt;BR /&gt;
       spouse  $20 sp_gender $1 sp_age 8&lt;BR /&gt;
       child1 $20 gender1 $1 rel1 $15 age1 8&lt;BR /&gt;
       child2 $20 gender2 $1 rel2 $15 age2 8 &lt;BR /&gt;
       street $20 city $15 state $2 zip $5;&lt;BR /&gt;
      &lt;BR /&gt;
retain employee emp_gender emp_age  spouse sp_gender sp_age &lt;BR /&gt;
       child1 gender1 rel1 age1 &lt;BR /&gt;
       child2 gender2 rel2  age2 &lt;BR /&gt;
       street city state zip; &lt;BR /&gt;
       	                                                  &lt;BR /&gt;
infile 'c:\temp\famdata.txt' dsd dlm = ',' end=eof;&lt;BR /&gt;
** read in record indicator and hold the line with trailing @;&lt;BR /&gt;
input recind $ @;&lt;BR /&gt;
                                                   &lt;BR /&gt;
  ** now, read in the other data lines, depending on the record indicator value;&lt;BR /&gt;
  if recind = 'e1' then do;&lt;BR /&gt;
     if _n_ gt 1 then do;&lt;BR /&gt;
	    ** this OUTPUT is for ALL the employee information except the last employee.;&lt;BR /&gt;
	    ** also, do NOT want to output when _N_= 1 because we have only read the first employee data line;&lt;BR /&gt;
	    ** at this point and we want to read the rest of his info before doing the output.;&lt;BR /&gt;
	    ** the logic is that every time we read an "e1" data line, we are reading in a NEW employee and must;&lt;BR /&gt;
	    ** output the info for the PREVIOUS employee.;&lt;BR /&gt;
        output;&lt;BR /&gt;
		                       &lt;BR /&gt;
		** initialize all variables to missing to erase previously retained information;&lt;BR /&gt;
		emp_gender=' '; sp_gender = ' '; emp_age = .; sp_age = .;&lt;BR /&gt;
		age1=.; age2=.; gender1=' '; gender2 = ' '; rel1 = ' '; rel2 = ' ';&lt;BR /&gt;
		child1 = ' '; child2 = ' '; spouse = ' '; street=' '; city=' '; state = ' '; zip = ' ';&lt;BR /&gt;
	 end;&lt;BR /&gt;
	 ** read in the employee record;&lt;BR /&gt;
	 input employee $ emp_gender $ emp_age;&lt;BR /&gt;
  end;&lt;BR /&gt;
  else if recind = 's1' then do;&lt;BR /&gt;
     input spouse $ sp_gender $ sp_age;&lt;BR /&gt;
  end;&lt;BR /&gt;
  else if recind = 'c1' then do;&lt;BR /&gt;
     input rel1 $ age1 child1 $ gender1 $;&lt;BR /&gt;
  end;&lt;BR /&gt;
  else if recind = 'c2' then do;&lt;BR /&gt;
     input rel2 $ age2 child2 $ gender2 $;&lt;BR /&gt;
  end;&lt;BR /&gt;
  else if recind = 'a1' then do;&lt;BR /&gt;
     input street $ city $ state $ zip $;&lt;BR /&gt;
  end;&lt;BR /&gt;
  if eof = 1 then do;&lt;BR /&gt;
     ** output LAST assembled obs for last employee because have reached end of file;&lt;BR /&gt;
     output;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
                                                  &lt;BR /&gt;
options nodate nonumber nocenter ls=200;&lt;BR /&gt;
proc print data=allrec;&lt;BR /&gt;
title 'use trailing @ and conditional output to assemble the whole obs from multiple input lines';&lt;BR /&gt;
run;&lt;BR /&gt;
            &lt;BR /&gt;
[/pre]</description>
      <pubDate>Sun, 11 Jan 2009 16:31:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64021#M13924</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-01-11T16:31:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in HL7 data into sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64022#M13925</link>
      <description>Thanks Cynthia. This worked for me. You are gr8.&lt;BR /&gt;
&lt;BR /&gt;
regards,&lt;BR /&gt;
sasbase</description>
      <pubDate>Mon, 12 Jan 2009 18:04:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64022#M13925</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-01-12T18:04:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in HL7 data into sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64023#M13926</link>
      <description>Hi Cyndy,&lt;BR /&gt;
&lt;BR /&gt;
I need you help again wrt to this layout.&lt;BR /&gt;
&lt;BR /&gt;
If any of the segments are repeating within for few of the records, how to get a hold of values for repeated segments??&lt;BR /&gt;
&lt;BR /&gt;
For ex: &lt;BR /&gt;
&lt;BR /&gt;
e1|abc|1123|09889&lt;BR /&gt;
a1|Dan|Peter|||&lt;BR /&gt;
dx1|1234|1&lt;BR /&gt;
dx1|33455|2&lt;BR /&gt;
dx1|34556|3&lt;BR /&gt;
c1|pete|||&lt;BR /&gt;
e1| &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
thanks,&lt;BR /&gt;
sasbase9</description>
      <pubDate>Fri, 26 Jun 2009 15:20:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64023#M13926</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-26T15:20:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in HL7 data into sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64024#M13927</link>
      <description>Consider that this is a general forum with individuals other than Cynthia.&lt;BR /&gt;
&lt;BR /&gt;
Also, what's unclear is the desired output result - please list both INPUT and OUTPUT (desired) data samples, for a meaningful reply by any of the subscribers on the forum.  I suspect you're interested in how to handle the "dx1" data (segment) strings, correct?  On the input side, these appear as separate records/segments -- how do you expect them to be represented, and how are they being represented with the current SAS program you are using (suggestion to post what code you have working today).&lt;BR /&gt;
&lt;BR /&gt;
As a courtesy, also, consider creating a new post next time with a reference to the prior post (hyperlink pasted in the new forum post works), given that it's pretty much a new question/query.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 26 Jun 2009 15:39:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64024#M13927</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-06-26T15:39:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in HL7 data into sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64025#M13928</link>
      <description>That's fine...I thought I can link up with Cyndy. Sorry about that.&lt;BR /&gt;
&lt;BR /&gt;
So my question is if I want to write out all of the data from segments e1 thru a1 into one record and to ctach all of the values inside repeated segments like DX1 , how to do that in sas program.&lt;BR /&gt;
When I am reading dx1 segments, it is ignoring what ever comes first if repeated and outputting only last value from the DX1 segment. I want to wrte out all values from DX1 from each of the repeated to a single record along with other variables.&lt;BR /&gt;
&lt;BR /&gt;
thanks for you help!!</description>
      <pubDate>Fri, 26 Jun 2009 15:57:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64025#M13928</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-26T15:57:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in HL7 data into sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64026#M13929</link>
      <description>Share your code please.  It's a guessing game otherwise.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 26 Jun 2009 16:20:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64026#M13929</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-06-26T16:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in HL7 data into sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64027#M13930</link>
      <description>Given below as my data -&lt;BR /&gt;
&lt;BR /&gt;
(removed as per user) &lt;BR /&gt;
&lt;BR /&gt;
I am using below code annd my code is not reading the repeated DX1 segments/PT2 segments. writing out one last segment.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Is this helps ??&lt;BR /&gt;
&lt;BR /&gt;
thanks,&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Sasbase

Message was edited by: Sasbase</description>
      <pubDate>Fri, 26 Jun 2009 19:44:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64027#M13930</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-26T19:44:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in HL7 data into sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64028#M13931</link>
      <description>It's clear that your "output logic" is only executed (once) after a specific set of input segment-types have been read up.  From what I can see, the code is not designed to handle multiple segments of the same type.  So, that stated, what would you expect to see in the output where you have multiple instances of a particular segment type?&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 26 Jun 2009 19:58:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64028#M13931</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-06-26T19:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in HL7 data into sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64029#M13932</link>
      <description>In Mulitiple sgements like PT2, I want to get a hold of SSN, member ID and Group whereever data is populated. My current code is reading only one of PT2 (last one )&lt;BR /&gt;
&lt;BR /&gt;
When writing out the claim record, I want to write out the needed info from the repeated segments - like SSN, MemberID from PT2 and From DX1 (they are diagnosis codes )  - may need to write out all of them where ever populated, else the ones came in.&lt;BR /&gt;
&lt;BR /&gt;
thanks,</description>
      <pubDate>Fri, 26 Jun 2009 20:02:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-in-HL7-data-into-sas/m-p/64029#M13932</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-26T20:02:48Z</dc:date>
    </item>
  </channel>
</rss>

