<?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 fill out a variable by looking at the next line in HL7 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/fill-out-a-variable-by-looking-at-the-next-line-in-HL7/m-p/560893#M156962</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am trying to think of marking a record with 'Y' if the next line in the file starts with 'NTE' and 'N'&amp;nbsp;f the next line in the file does not start with 'NTE'.&lt;/P&gt;&lt;P&gt;I am using the following program to create a dataset of OBX records and I want to add a column named 'has_NTE'&amp;nbsp; which would basically say whether a specific OBX record has an NTE a trailing segment and/or record.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* get the max column count of non-missing columns;
data _null_;
   retain column_count;
   count=0;
   infile obx end=eof;
   input;
   if _infile_ =: "OBX" then
   do i=1 to countc(_infile_,"|^")+1;
   count+1;
      column_count=max(column_count,count);
   end;
   if eof then call symputx("column_count",column_count);
run;
%put &amp;amp;=column_count;

data OBX;
   infile obx lrecl=32767;
   ID=_N_;
   length var1-var&amp;amp;column_count $100;
   array vars{*} var:;
   input;
   if _infile_ =: "OBX";
   do i=1 to dim(vars);
      vars{i}=scan(_infile_,i,"|^",'M');
   end;
   drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want my output column to be 'Y' for the following scenario:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OBX|1|ST|13457-7^^LOINC^25016900^LDL-CHOLESTEROL^L||SEE NOTE|mg/dL (calc)|^99^||||F|||201901030942|||&lt;BR /&gt;NTE|1||&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And&amp;nbsp;I want my output column to be 'N' for any other scenarios&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me enhancing the code. Thanks is advance. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 22 May 2019 16:58:59 GMT</pubDate>
    <dc:creator>mosabbirfardin</dc:creator>
    <dc:date>2019-05-22T16:58:59Z</dc:date>
    <item>
      <title>fill out a variable by looking at the next line in HL7</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fill-out-a-variable-by-looking-at-the-next-line-in-HL7/m-p/560893#M156962</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am trying to think of marking a record with 'Y' if the next line in the file starts with 'NTE' and 'N'&amp;nbsp;f the next line in the file does not start with 'NTE'.&lt;/P&gt;&lt;P&gt;I am using the following program to create a dataset of OBX records and I want to add a column named 'has_NTE'&amp;nbsp; which would basically say whether a specific OBX record has an NTE a trailing segment and/or record.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* get the max column count of non-missing columns;
data _null_;
   retain column_count;
   count=0;
   infile obx end=eof;
   input;
   if _infile_ =: "OBX" then
   do i=1 to countc(_infile_,"|^")+1;
   count+1;
      column_count=max(column_count,count);
   end;
   if eof then call symputx("column_count",column_count);
run;
%put &amp;amp;=column_count;

data OBX;
   infile obx lrecl=32767;
   ID=_N_;
   length var1-var&amp;amp;column_count $100;
   array vars{*} var:;
   input;
   if _infile_ =: "OBX";
   do i=1 to dim(vars);
      vars{i}=scan(_infile_,i,"|^",'M');
   end;
   drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want my output column to be 'Y' for the following scenario:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OBX|1|ST|13457-7^^LOINC^25016900^LDL-CHOLESTEROL^L||SEE NOTE|mg/dL (calc)|^99^||||F|||201901030942|||&lt;BR /&gt;NTE|1||&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And&amp;nbsp;I want my output column to be 'N' for any other scenarios&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me enhancing the code. Thanks is advance. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2019 16:58:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fill-out-a-variable-by-looking-at-the-next-line-in-HL7/m-p/560893#M156962</guid>
      <dc:creator>mosabbirfardin</dc:creator>
      <dc:date>2019-05-22T16:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: fill out a variable by looking at the next line in HL7</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fill-out-a-variable-by-looking-at-the-next-line-in-HL7/m-p/560969#M156964</link>
      <description>&lt;P&gt;Hi! I would suggest merging the dataset with itself to simulate a "lead" function:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/kb/24/666.html" target="_blank"&gt;http://support.sas.com/kb/24/666.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2019 20:37:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fill-out-a-variable-by-looking-at-the-next-line-in-HL7/m-p/560969#M156964</guid>
      <dc:creator>KDG</dc:creator>
      <dc:date>2019-05-22T20:37:49Z</dc:date>
    </item>
    <item>
      <title>Re: fill out a variable by looking at the next line in HL7</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fill-out-a-variable-by-looking-at-the-next-line-in-HL7/m-p/560982#M156972</link>
      <description>&lt;P&gt;There are some very good reasons to code Yes/No or True/False as numeric 1 and 0 instead of character values.&lt;/P&gt;
&lt;P&gt;Report procedures like Proc Report or Tabulate you can use the N statistic to get the number of responses, the SUM statistic to get the number of Yes, the MEAN statistic to get a percentage of yes, Range to tell if all of the responses in a group are the same (either all 0 or all 1 when the Range=0) , MAX to find if any of the records were coded yes (when the MAX=1), MIN to find if any were coded No (when the Min=0).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another is you can use: if code then &amp;lt;whatever&amp;gt;; as SAS treats 1 as true .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are even some interesting calculations that can be done with code bits like: code*(some calculations) which return 0 for that when code is no.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2019 22:13:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fill-out-a-variable-by-looking-at-the-next-line-in-HL7/m-p/560982#M156972</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-22T22:13:15Z</dc:date>
    </item>
    <item>
      <title>Re: fill out a variable by looking at the next line in HL7</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fill-out-a-variable-by-looking-at-the-next-line-in-HL7/m-p/560987#M156975</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sk / view=sk;
   sk+1;
   set sashelp.class;
run;

proc sql;
   create table lead as
   select
      a.name
     ,b.name as next_name
   from
      sk a
   left join 
      sk b
   on 
      a.sk=b.sk-1
   ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 May 2019 23:21:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fill-out-a-variable-by-looking-at-the-next-line-in-HL7/m-p/560987#M156975</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-05-22T23:21:59Z</dc:date>
    </item>
    <item>
      <title>Re: fill out a variable by looking at the next line in HL7</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fill-out-a-variable-by-looking-at-the-next-line-in-HL7/m-p/561169#M157041</link>
      <description>&lt;P&gt;Thanks everyone for your guidance. I kind of figured it out by myself.&lt;/P&gt;&lt;P&gt;As you are all aware of the hierarchical structure of HL7 files, it seems one NTE segments or a group of NTE segments will always follow an OBX segment but not all OBX segments are followed by NTE segment(s). In my file the first NTE comes at 18th line and 17th line is an OBX segment.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So what I did was:&lt;/P&gt;&lt;P&gt;1. Get observation numbers of each NTE segments and OBX segments by using ID=_N_ and create 2 separate datasets (OBX and NTE)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NTE dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sas1.PNG" style="width: 411px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29720i717BD7FBCCDEF061/image-size/large?v=v2&amp;amp;px=999" role="button" title="sas1.PNG" alt="sas1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Partial OBX dataset:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sas3.PNG" style="width: 467px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29722i8416D915B0DF0323/image-size/large?v=v2&amp;amp;px=999" role="button" title="sas3.PNG" alt="sas3.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Subtract 1 from the ID column for NTE segments. I saw a series of incremental ID from which the lowest number would represent the observation numbers (OBX_ID) of the corresponding OBX segments.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sas2.PNG" style="width: 411px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29721iDE67DBA3536D458C/image-size/large?v=v2&amp;amp;px=999" role="button" title="sas2.PNG" alt="sas2.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3.I assigned NTE_SK to each NTE&amp;nbsp; records using the following code so that I can group them together later.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if set_id_NTE=1 then NTE_SK+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dataset with NTE_SK:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sas10.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29729i16002388A5C31A6D/image-size/large?v=v2&amp;amp;px=999" role="button" title="sas10.PNG" alt="sas10.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4.Then I transposed the NTE dataset and flattened it. This gave me 2 types of records. One holds the whole comment for the OBX segment and the other holds a bunch of numbers from which the lowest number would represent the observation numbers of the corresponding OBX segments.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=WORK.NTE_WITH_ID out=WORK.TRANSPOSED_NTE prefix=x;

   by NTE_SK;

   var COMMENT previous_OBX_ID;

run;

data WORK.FLATTENED_NTE;

   set WORK.TRANSPOSED_NTE;
   LENGTH FULL_COMMENT $3000;
   FULL_COMMENT = CATX(' ', OF X:);
   keep NTE_SK _NAME_ FULL_COMMENT previous_OBX_ID;
   DROP X:;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Transposed NTE dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sas4.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29723i8D69BD61A8A1B664/image-size/large?v=v2&amp;amp;px=999" role="button" title="sas4.PNG" alt="sas4.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Flattened NTE dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sas5.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29724iBAD4A6D7260B158F/image-size/large?v=v2&amp;amp;px=999" role="button" title="sas5.PNG" alt="sas5.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;5. Then I split the dataset into 2 datasets using the type of records. One would have just the comments and other would have just the incremental numbers&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* define which libname.member table, and by which column */
%let TABLE=WORK.FLATTENED_NTE;
%let COLUMN=_NAME_;
 
proc sql NOPRINT;
/* build a mini program for each value */
/* create a table with valid chars from data value */
select distinct 
   cat("DATA NTE_",compress(&amp;amp;COLUMN.,,'kad'),
   "; set &amp;amp;TABLE.(where=(&amp;amp;COLUMN.='", &amp;amp;COLUMN.,
   "')); run;") length=500 into :allsteps separated by ';' 
  from &amp;amp;TABLE.;
quit;
 
/* macro that includes the program we just generated */
%macro runSteps;
 &amp;amp;allsteps.;
%mend;
 
/* and...run the macro when ready */
%runSteps;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just comments:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sas6.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29725iD646A31E9CAC3CD7/image-size/large?v=v2&amp;amp;px=999" role="button" title="sas6.PNG" alt="sas6.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just numbers:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sas7.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29726i1B6814B134787DA2/image-size/large?v=v2&amp;amp;px=999" role="button" title="sas7.PNG" alt="sas7.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;6. I used a SCAN function on the FULL_COMMENT in the numbers' dataset to get the first number which would be the OBX_ID.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sas8.PNG" style="width: 334px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29727iCD7E2076EB3CE63F/image-size/large?v=v2&amp;amp;px=999" role="button" title="sas8.PNG" alt="sas8.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;7. Then I joined this dataset with comment dataset using NTE_SK and now I have an OBX_ID with every comments to join OBX table with.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry for this huge post. I know I have done a lot of post processing to get where I am now. I would really appreciate if someone shares a faster and more efficient approach to do this. Take care!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 May 2019 14:40:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fill-out-a-variable-by-looking-at-the-next-line-in-HL7/m-p/561169#M157041</guid>
      <dc:creator>mosabbirfardin</dc:creator>
      <dc:date>2019-05-23T14:40:30Z</dc:date>
    </item>
  </channel>
</rss>

