<?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: display separate record for each condition that is satisfied in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/display-separate-record-for-each-condition-that-is-satisfied/m-p/942936#M369680</link>
    <description>&lt;P&gt;Hello, Thank you!! Proc transpose worked &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; just got the request updated-- I would like to get all other variables present in the dataset like result, unit, range etc. along with the SubjectID and test name. All corresponding lab variables are labeled as Result1-13, Unit1-13, Range1-13 like Lab1-13&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data Lab;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input Subjid $ Lab1 Lab2 Lab3 Lab4 Lab5 Lab6 Lab7 Lab8 Lab9 Lab10 Lab11 Lab12 Lab13 Result1 Result2 Result3 Result4 Result5 Result6 Result7 Result8 Result9 Result10 Result11 Result12 Result13 ;&lt;BR /&gt;datalines;&lt;BR /&gt;Subj1 1 3 3 1 1 1 1 2 . 1 1 1 1 01 02 03 04 05 06 07 08 . 010 011 012 013&lt;BR /&gt;Subj2 1 1 1 1 1 1 1 1 1 1 1 . 3 011 012 013 014 015 016 017 018 019 0110 0111 . 0113&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Get ALL respective variables like result, unit, range etc. for the records with Any Lab from 1 to 13 has value 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data Want;&lt;/P&gt;&lt;P&gt;Subject Lab Name Lab Result Lab Units etc..&lt;BR /&gt;--------------------------------------------------&lt;BR /&gt;Subj1 Lab2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02&lt;BR /&gt;Subj1 Lab3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;03&lt;BR /&gt;Subj2 Lab13&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0113&lt;/P&gt;</description>
    <pubDate>Fri, 06 Sep 2024 17:57:40 GMT</pubDate>
    <dc:creator>SAS-PD</dc:creator>
    <dc:date>2024-09-06T17:57:40Z</dc:date>
    <item>
      <title>display separate record for each condition that is satisfied</title>
      <link>https://communities.sas.com/t5/SAS-Programming/display-separate-record-for-each-condition-that-is-satisfied/m-p/942767#M369643</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have 13 different labs for each subject; I need to list all lab test name as a list for each where value is 3&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data Lab;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input Subjid $ Lab1 Lab2 Lab3 Lab4 Lab5 Lab6 Lab7 Lab8 Lab9 Lab10 Lab11 Lab12 Lab13 ;&lt;BR /&gt;datalines;&lt;BR /&gt;Subj1 1 3 3 1 1 1 1 2 . 1 1 1 1&lt;BR /&gt;Subj2 1 1 1 1 1 1 1 1 1 1 1 . 3&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Get records with Any Lab from 1 to 13 has value 3&lt;/P&gt;&lt;P&gt;data lab_1;&lt;BR /&gt;set Lab ;&lt;BR /&gt;where (Lab1 = 3 OR&lt;BR /&gt;Lab2 = 3 OR&lt;BR /&gt;Lab3 = 3 OR&lt;BR /&gt;Lab4 = 3 OR&lt;BR /&gt;Lab5 = 3 OR&lt;BR /&gt;Lab6 = 3 OR&lt;BR /&gt;Lab7 = 3 OR&lt;BR /&gt;Lab8 = 3 OR&lt;BR /&gt;Lab9 = 3 OR&lt;BR /&gt;Lab10 = 3 OR&lt;BR /&gt;Lab11 = 3 OR&lt;BR /&gt;Lab12 = 3 OR&lt;BR /&gt;Lab13 = 3 );&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Need help to display Lab Name as separate records if value = 3&lt;/P&gt;&lt;P&gt;Data Want;&lt;/P&gt;&lt;P&gt;Subject&amp;nbsp; &amp;nbsp; &amp;nbsp;Lab Name&lt;BR /&gt;----------------------&lt;BR /&gt;Subj1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Lab2&lt;BR /&gt;Subj1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Lab3&lt;BR /&gt;Subj2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Lab13&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2024 17:26:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/display-separate-record-for-each-condition-that-is-satisfied/m-p/942767#M369643</guid>
      <dc:creator>SAS-PD</dc:creator>
      <dc:date>2024-09-05T17:26:25Z</dc:date>
    </item>
    <item>
      <title>Re: display separate record for each condition that is satisfied</title>
      <link>https://communities.sas.com/t5/SAS-Programming/display-separate-record-for-each-condition-that-is-satisfied/m-p/942778#M369645</link>
      <description>&lt;P&gt;If SUBJID is not repeated:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc transpose data=lab out=labtrans;
   by subjid;
   var lab: ;
run;

proc print data=labtrans noobs label;
  where col1=3;
  var subjid _name_;
  label _name_ ='Lab name';
run;&lt;/PRE&gt;
&lt;P&gt;You would have to sort the Lab data set by Subjid if it is not in that order OR use the Notsorted option on the BY statement in the Proc Transpose step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will find that for many processes long beats wide. That means one observation per similar measurements (per lab in this case) with a variable holding where the measure comes from (the lab name).&lt;/P&gt;
&lt;P&gt;Proc Transpose is one tool that may get to that data structure.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2024 18:06:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/display-separate-record-for-each-condition-that-is-satisfied/m-p/942778#M369645</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-09-05T18:06:04Z</dc:date>
    </item>
    <item>
      <title>Re: display separate record for each condition that is satisfied</title>
      <link>https://communities.sas.com/t5/SAS-Programming/display-separate-record-for-each-condition-that-is-satisfied/m-p/942799#M369649</link>
      <description>&lt;P&gt;It would be much easier if you just read it in that way to begin with.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Lab;
  input Subjid $ @;
  do lab=1 to 13 ;
    input result @ ;
    output;
  end;
datalines;
Subj1 1 3 3 1 1 1 1 2 . 1 1 1 1
Subj2 1 1 1 1 1 1 1 1 1 1 1 . 3
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then a simple WHERE statement will suffice.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=lab;
 where result=3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    Subjid    lab    result

  2    Subj1       2       3
  3    Subj1       3       3
 26    Subj2      13       3

&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Sep 2024 18:54:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/display-separate-record-for-each-condition-that-is-satisfied/m-p/942799#M369649</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-09-05T18:54:25Z</dc:date>
    </item>
    <item>
      <title>Re: display separate record for each condition that is satisfied</title>
      <link>https://communities.sas.com/t5/SAS-Programming/display-separate-record-for-each-condition-that-is-satisfied/m-p/942842#M369660</link>
      <description>&lt;P&gt;You can use the VNAME function:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Lab;
infile datalines;
input Subjid $ Lab1 Lab2 Lab3 Lab4 Lab5 Lab6 Lab7 Lab8 Lab9 Lab10 Lab11 Lab12 Lab13 ;
datalines;
Subj1 1 3 3 1 1 1 1 2 . 1 1 1 1
Subj2 1 1 1 1 1 1 1 1 1 1 1 . 3
;
run;

data want (keep=subjid labname);
  set lab;
  array labs  lab1-lab13 ;
  do over labs;
    if labs=3 then do;
      labname=vname(labs);
      output;
    end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Sep 2024 03:14:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/display-separate-record-for-each-condition-that-is-satisfied/m-p/942842#M369660</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-09-06T03:14:43Z</dc:date>
    </item>
    <item>
      <title>Re: display separate record for each condition that is satisfied</title>
      <link>https://communities.sas.com/t5/SAS-Programming/display-separate-record-for-each-condition-that-is-satisfied/m-p/942936#M369680</link>
      <description>&lt;P&gt;Hello, Thank you!! Proc transpose worked &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; just got the request updated-- I would like to get all other variables present in the dataset like result, unit, range etc. along with the SubjectID and test name. All corresponding lab variables are labeled as Result1-13, Unit1-13, Range1-13 like Lab1-13&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data Lab;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input Subjid $ Lab1 Lab2 Lab3 Lab4 Lab5 Lab6 Lab7 Lab8 Lab9 Lab10 Lab11 Lab12 Lab13 Result1 Result2 Result3 Result4 Result5 Result6 Result7 Result8 Result9 Result10 Result11 Result12 Result13 ;&lt;BR /&gt;datalines;&lt;BR /&gt;Subj1 1 3 3 1 1 1 1 2 . 1 1 1 1 01 02 03 04 05 06 07 08 . 010 011 012 013&lt;BR /&gt;Subj2 1 1 1 1 1 1 1 1 1 1 1 . 3 011 012 013 014 015 016 017 018 019 0110 0111 . 0113&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Get ALL respective variables like result, unit, range etc. for the records with Any Lab from 1 to 13 has value 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data Want;&lt;/P&gt;&lt;P&gt;Subject Lab Name Lab Result Lab Units etc..&lt;BR /&gt;--------------------------------------------------&lt;BR /&gt;Subj1 Lab2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02&lt;BR /&gt;Subj1 Lab3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;03&lt;BR /&gt;Subj2 Lab13&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0113&lt;/P&gt;</description>
      <pubDate>Fri, 06 Sep 2024 17:57:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/display-separate-record-for-each-condition-that-is-satisfied/m-p/942936#M369680</guid>
      <dc:creator>SAS-PD</dc:creator>
      <dc:date>2024-09-06T17:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: display separate record for each condition that is satisfied</title>
      <link>https://communities.sas.com/t5/SAS-Programming/display-separate-record-for-each-condition-that-is-satisfied/m-p/942938#M369682</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/466333"&gt;@SAS-PD&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello, Thank you!! Proc transpose worked &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; just got the request updated-- I would like to get all other variables present in the dataset like result, unit, range etc. along with the SubjectID and test name. All corresponding lab variables are labeled as Result1-13, Unit1-13, Range1-13 like Lab1-13&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data Lab;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input Subjid $ Lab1 Lab2 Lab3 Lab4 Lab5 Lab6 Lab7 Lab8 Lab9 Lab10 Lab11 Lab12 Lab13 Result1 Result2 Result3 Result4 Result5 Result6 Result7 Result8 Result9 Result10 Result11 Result12 Result13 ;&lt;BR /&gt;datalines;&lt;BR /&gt;Subj1 1 3 3 1 1 1 1 2 . 1 1 1 1 01 02 03 04 05 06 07 08 . 010 011 012 013&lt;BR /&gt;Subj2 1 1 1 1 1 1 1 1 1 1 1 . 3 011 012 013 014 015 016 017 018 019 0110 0111 . 0113&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;Get ALL respective variables like result, unit, range etc. for the records with Any Lab from 1 to 13 has value 3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data Want;&lt;/P&gt;
&lt;P&gt;Subject Lab Name Lab Result Lab Units etc..&lt;BR /&gt;--------------------------------------------------&lt;BR /&gt;Subj1 Lab2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02&lt;BR /&gt;Subj1 Lab3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;03&lt;BR /&gt;Subj2 Lab13&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0113&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then make a second array for result1-result13 to parallel lab1-lab13:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (keep=subjid labname result);
  set lab;
  array labs  lab1-lab13 ;
  array rslts result1-result13;
  do over labs;
    if labs=3 then do;
      labname=vname(labs);
      result=rslts;
      output;
    end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Sep 2024 18:05:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/display-separate-record-for-each-condition-that-is-satisfied/m-p/942938#M369682</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-09-06T18:05:09Z</dc:date>
    </item>
  </channel>
</rss>

