<?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 Transposing Multiple Variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Transposing-Multiple-Variables/m-p/253729#M309800</link>
    <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a taks to perform, and the only thing I managed to get working, is long and unefficient.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a datase with clinical laboratory results, along with reference values, the data has the following variables:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Subject ID&lt;/LI&gt;&lt;LI&gt;Visit (ranging from 1-4, i.e. each subject has up to 4 rows in this data)&lt;/LI&gt;&lt;LI&gt;Treatment group (1/0)&lt;/LI&gt;&lt;LI&gt;Test 1 (Numeric)&lt;/LI&gt;&lt;LI&gt;Test 2 (Numeric)&lt;/LI&gt;&lt;LI&gt;Test 3 (Numeric)&lt;/LI&gt;&lt;LI&gt;Test 1 Low reference value (numeric)&lt;/LI&gt;&lt;LI&gt;Test 1 High reference value (numeric)&lt;/LI&gt;&lt;LI&gt;Test 2 Low reference value (numeric)&lt;/LI&gt;&lt;LI&gt;Test 2 High reference value (numeric)&lt;/LI&gt;&lt;LI&gt;Test 3 Low reference value (numeric)&lt;/LI&gt;&lt;LI&gt;Test 3 High reference value (numeric)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;My final goal is to present descriptive statistics for the numeric tests and frequency distributions of the tests within range.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to do the analysis with the "by" statment, to save code (write it once).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My problem is to bring the data to the shape I need. I do not want to calculate the within normal range variable 3 times, I want it only once, but I can't seem to manage that. So I did it "widthly" which means copy+paste. The if statment is long (4 conditions) and copying it 3 times (what if I'll have 13?) is prone to bugs. How can I create a data, with each row corresponding to a subject*visit*treatment*test, with the normality status matching the right test?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Comment: Clearly I can't add data, but feel free to type any numbers you wish, the principle matters, not the numbers.&lt;/P&gt;</description>
    <pubDate>Wed, 02 Mar 2016 10:07:58 GMT</pubDate>
    <dc:creator>BlueNose</dc:creator>
    <dc:date>2016-03-02T10:07:58Z</dc:date>
    <item>
      <title>Transposing Multiple Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-Multiple-Variables/m-p/253729#M309800</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a taks to perform, and the only thing I managed to get working, is long and unefficient.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a datase with clinical laboratory results, along with reference values, the data has the following variables:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Subject ID&lt;/LI&gt;&lt;LI&gt;Visit (ranging from 1-4, i.e. each subject has up to 4 rows in this data)&lt;/LI&gt;&lt;LI&gt;Treatment group (1/0)&lt;/LI&gt;&lt;LI&gt;Test 1 (Numeric)&lt;/LI&gt;&lt;LI&gt;Test 2 (Numeric)&lt;/LI&gt;&lt;LI&gt;Test 3 (Numeric)&lt;/LI&gt;&lt;LI&gt;Test 1 Low reference value (numeric)&lt;/LI&gt;&lt;LI&gt;Test 1 High reference value (numeric)&lt;/LI&gt;&lt;LI&gt;Test 2 Low reference value (numeric)&lt;/LI&gt;&lt;LI&gt;Test 2 High reference value (numeric)&lt;/LI&gt;&lt;LI&gt;Test 3 Low reference value (numeric)&lt;/LI&gt;&lt;LI&gt;Test 3 High reference value (numeric)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;My final goal is to present descriptive statistics for the numeric tests and frequency distributions of the tests within range.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to do the analysis with the "by" statment, to save code (write it once).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My problem is to bring the data to the shape I need. I do not want to calculate the within normal range variable 3 times, I want it only once, but I can't seem to manage that. So I did it "widthly" which means copy+paste. The if statment is long (4 conditions) and copying it 3 times (what if I'll have 13?) is prone to bugs. How can I create a data, with each row corresponding to a subject*visit*treatment*test, with the normality status matching the right test?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Comment: Clearly I can't add data, but feel free to type any numbers you wish, the principle matters, not the numbers.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2016 10:07:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-Multiple-Variables/m-p/253729#M309800</guid>
      <dc:creator>BlueNose</dc:creator>
      <dc:date>2016-03-02T10:07:58Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing Multiple Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-Multiple-Variables/m-p/253735#M309801</link>
      <description>&lt;P&gt;If you search here, or on the internet for "reshape data" or "long to wide" you will find many posts on the subject, with various solutions from macro code, arrays etc. &amp;nbsp;Without seeing an example of what your data looks like, or what you want the output to look like I can't provide code though.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2016 10:27:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-Multiple-Variables/m-p/253735#M309801</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-03-02T10:27:00Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing Multiple Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-Multiple-Variables/m-p/253736#M309802</link>
      <description>&lt;P&gt;the data looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data A;&lt;/P&gt;&lt;P&gt;input ID Visit Group Test1 Test2 Test3 Test1_L Test1_H Test2_L Test2_H Test3_L Test3_H;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 1 0 5 3 6.7 1 10 2 7 3 9&lt;/P&gt;&lt;P&gt;1 2 0 5.5 3.8 8.7 1 10 2 7 3 9&lt;/P&gt;&lt;P&gt;1 3 0 4.5 2.8 5.7 1 10 2 7 3 9&lt;/P&gt;&lt;P&gt;2 1 1 .......&lt;/P&gt;&lt;P&gt;2 2 1 ......&lt;/P&gt;&lt;P&gt;2 3 1 ......&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want at the end is that each row will represent one subject, in one visit, for one single test, I want the row to include the value of the test, and a character variable: "Normal" or "Not normal" according to the reference values (low and high) of the test. And, i want to keep the group of course. Test1 is normal if it is within Test1_L and Test1_H, and so on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried looking, couldn't find what I need.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2016 10:33:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-Multiple-Variables/m-p/253736#M309802</guid>
      <dc:creator>BlueNose</dc:creator>
      <dc:date>2016-03-02T10:33:15Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing Multiple Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-Multiple-Variables/m-p/253744#M309803</link>
      <description>&lt;P&gt;Assuming the prefix is constant:&lt;/P&gt;
&lt;PRE&gt;data A;
  input ID Visit Group Test1 Test2 Test3 Test1_L Test1_H Test2_L Test2_H Test3_L Test3_H;
datalines;
1 1 0 5 3 6.7 1 10 2 7 3 9
1 2 0 5.5 3.8 8.7 1 10 2 7 3 9
1 3 0 4.5 2.8 5.7 1 10 2 7 3 9
;
run;

proc transpose data=a out=want;
  by id visit group;
  var test:;
run;
&lt;/PRE&gt;
&lt;P&gt;Will transpose the data down. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your other question, regarding the ranges, you have really made a rod for your own back there with that layout. &amp;nbsp;TestX is fine, but because you have not put the incrementor at the end of test_hX for instance, its harder to reference them.&lt;/P&gt;
&lt;PRE&gt;data A;
  input ID Visit Group Test1 Test2 Test3 Test1_L Test1_H Test2_L Test2_H Test3_L Test3_H;
datalines;
1 1 0 5 3 6.7 1 10 2 7 3 9
1 2 0 5.5 3.8 8.7 1 10 2 7 3 9
1 3 0 4.5 2.8 5.7 1 10 2 7 3 9
;
run;

data b;
  set a;
  array test{3};
  array test_h{3} test1_h test2_h test3_h;
  array test_l{3} test1_l test2_l test3_l;
  array test_result{3} $50;
  do i=1 to 3;
    if test_l{i} &amp;lt;= test{i} &amp;lt;= test_h{i} then test_result{i}="Normal";
    else test_result{i}="Not Normal";
  end;
run;


proc transpose data=b out=want;
  by id visit group;
  var test:;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Mar 2016 10:59:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-Multiple-Variables/m-p/253744#M309803</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-03-02T10:59:49Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing Multiple Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-Multiple-Variables/m-p/253752#M309804</link>
      <description>&lt;P&gt;This method transposes the LAB test and makes no assumption about the name (i.e. TEST1) only that the high and low range values are identified by adding _H or _L to the root name. &amp;nbsp;I will leave it to you to calculated the range flag. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A;
   input ID Visit Group Test1 Test2 Test3 Test1_L Test1_H Test2_L Test2_H Test3_L Test3_H;
   datalines;
1 1 0 5 3 6.7 1 10 2 7 3 9
1 2 0 5.5 3.8 8.7 1 10 2 7 3 9
1 3 0 4.5 2.8 5.7 1 10 2 7 3 9
2 1 1 5 3 6.7 1 10 2 7 3 9
2 2 1 5.5 3.8 8.7 1 10 2 7 3 9
2 3 1 4.5 2.8 5.7 1 10 2 7 3 9
;;;;
   run;
proc print;
   run;
proc transpose data=a out=b;
   by id visit group;
   run;
data b;
   set b;
   length paramcd $8 namecd $1;
   call scan(_name_,1,p,l,'_');
   paramcd = substrn(_name_,p,l);
   namecd  = coalesceC(substrn(_name_,p+l+1),'V');
   drop p l _name_;
   run;
proc sort data=b;
   by id visit group paramcd;
   run;
proc format;
   value $namecd 'V'='Value' 'H'='High' 'L'='Low';
   run;
proc transpose data=b out=c(drop=_name_);
   by id visit group paramcd;
   id namecd;
   format namecd $namecd.;
   var col1;
   run;
proc print;
   run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/2138i5D67DDF19BF242DC/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2016 11:29:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-Multiple-Variables/m-p/253752#M309804</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-03-02T11:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing Multiple Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-Multiple-Variables/m-p/253798#M309805</link>
      <description>&lt;P&gt;see&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://goo.gl/05M2EO" target="_blank"&gt;https://goo.gl/05M2EO&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you can have multiple variables on the id statement&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>Wed, 02 Mar 2016 13:32:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-Multiple-Variables/m-p/253798#M309805</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2016-03-02T13:32:43Z</dc:date>
    </item>
  </channel>
</rss>

