<?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: Merging and transposing rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merging-and-transposing-rows/m-p/260986#M50698</link>
    <description>&lt;P&gt;Please post what you have and what you're trying to achieve. Ideally, you should post this as text into the forum, rather than as an attachment. I don't like downloading files.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the instructions on how to create a data step of your data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&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>Mon, 04 Apr 2016 04:57:57 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-04-04T04:57:57Z</dc:date>
    <item>
      <title>Merging and transposing rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-and-transposing-rows/m-p/260985#M50697</link>
      <description>&lt;P&gt;Hi all&lt;/P&gt;
&lt;P&gt;I have a file which I attached, basically containing a table&amp;nbsp;with values for statistical analysis in rows per each covariate.&lt;/P&gt;
&lt;P&gt;I am trying to build another table from this one which would contain one row, basicly combining the rows per covariate into a line&lt;/P&gt;
&lt;P&gt;So for the covariate (white) for example, I wanted to have a row that looks like this:&lt;/P&gt;
&lt;P&gt;(White) followed by next row = value from O10 for&amp;nbsp;median (p25-p75) followed by p value (par_p1), then &amp;nbsp;value from O10 for mean(std), then value for (nonpar_p1)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would really appreciate any help. Tried to solve it with arrays but I am not s good at arrays&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Ammar&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2016 04:52:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-and-transposing-rows/m-p/260985#M50697</guid>
      <dc:creator>ammarhm</dc:creator>
      <dc:date>2016-04-04T04:52:16Z</dc:date>
    </item>
    <item>
      <title>Re: Merging and transposing rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-and-transposing-rows/m-p/260986#M50698</link>
      <description>&lt;P&gt;Please post what you have and what you're trying to achieve. Ideally, you should post this as text into the forum, rather than as an attachment. I don't like downloading files.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the instructions on how to create a data step of your data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&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>Mon, 04 Apr 2016 04:57:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-and-transposing-rows/m-p/260986#M50698</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-04T04:57:57Z</dc:date>
    </item>
    <item>
      <title>Re: Merging and transposing rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-and-transposing-rows/m-p/260987#M50699</link>
      <description>&lt;P&gt;Thank you Reza&lt;/P&gt;
&lt;P&gt;I usually put it down as a table in the text but I cant seem to figure out how to put to put an inline table as the tool for the table insesion seems to have disappeard (?)&lt;/P&gt;
&lt;P&gt;Thank you for your post regarding creating the data step, I am really not that expert with this kind of editing, I tried to look at the instruction but I got lost there...&lt;/P&gt;
&lt;P&gt;I appreciate your help and thank you for your kind reply&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;
&lt;P&gt;Am&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2016 05:16:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-and-transposing-rows/m-p/260987#M50699</guid>
      <dc:creator>ammarhm</dc:creator>
      <dc:date>2016-04-04T05:16:34Z</dc:date>
    </item>
    <item>
      <title>Re: Merging and transposing rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-and-transposing-rows/m-p/260988#M50700</link>
      <description>&lt;P&gt;Dear Reza&lt;/P&gt;
&lt;P&gt;Here is a datafile, created manually&lt;/P&gt;
&lt;P&gt;I hope this explains the idea further&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Am&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 have;
  infile datalines dsd truncover;
  input Covariate:$13. Statistic:$40. O10:$8. pvalue:$6.;
datalines4;
White,Median,22,0.1,
White,P25,5,0.1,
White,P75,66,0.1,
White,Mean,44,0.1.,
White,Std,12,0.1,
Red,Median,8,0.05,
Red,P25,4,0.05,
Red,P75,12,0.05,
Red,Mean,9,0.05,
Red,Std,3,0.05,
Black,Median,4,0.3,
Black,P25,2,0.3,
Black,P75,5,0.3,
Black,Mean,4,0.3,
Black,Std,2,0.3,
Blue,Median,77,0.001,
Blue,P25,44,0.001,
Blue,P75,88,0.001,
Blue,Mean,70,0.001,
Blue,Std,10,0.001

;;;;&lt;BR /&gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;And here is the correspong code for the file I want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile datalines dsd truncover;
  input Covariate:$13. median_qrange:$40. Mean_std:$8. pvalue:$6.;
datalines4;
White,22(5-66),44(12),0.1,
Red,8(4-12),9(3),0.05,
Black,4(2-5),4(2),0.3,
Blue,77(44-88),70(19),0.001,

;;;;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Apr 2016 05:52:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-and-transposing-rows/m-p/260988#M50700</guid>
      <dc:creator>ammarhm</dc:creator>
      <dc:date>2016-04-04T05:52:34Z</dc:date>
    </item>
    <item>
      <title>Re: Merging and transposing rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-and-transposing-rows/m-p/260993#M50702</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
format /* just for variable order */
  Covariate
  median_qrange
  mean_std
  pvalue
;
set have;
by Covariate notsorted;
retain median_qrange mean_std;
length
  median_qrange $40
  mean_std $8
;
if first.Covariate
then do;
  median_qrange = '';
  mean_std = '';
end;
prev_o10 = lag(O10);
if substr(median_qrange,length(median_qrange),1) = '(' then median_qrange = strip(median_qrange) !! strip(O10);
if Statistic = 'Median' then do;
  median_qrange = strip(O10) !! '(';
end;
if Statistic = 'Mean'
then do;
  median_qrange = strip(median_qrange) !! '-' !! strip(prev_o10) !! ')';
  mean_std = trim(O10) !! '(';
end;
if last.Covariate
then do;
  mean_std = trim(mean_std) !! trim(O10) !! ')';
  output;
end;
keep Covariate median_qrange mean_std pvalue;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Apr 2016 07:04:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-and-transposing-rows/m-p/260993#M50702</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-04-04T07:04:40Z</dc:date>
    </item>
    <item>
      <title>Re: Merging and transposing rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-and-transposing-rows/m-p/260999#M50704</link>
      <description>&lt;PRE&gt;

data have;
  infile datalines dsd truncover;
  input Covariate:$13. Statistic:$40. O10:$8. pvalue:$6.;
datalines4;
White,Median,22,0.1,
White,P25,5,0.1,
White,P75,66,0.1,
White,Mean,44,0.1,
White,Std,12,0.1,
Red,Median,8,0.05,
Red,P25,4,0.05,
Red,P75,12,0.05,
Red,Mean,9,0.05,
Red,Std,3,0.05,
Black,Median,4,0.3,
Black,P25,2,0.3,
Black,P75,5,0.3,
Black,Mean,4,0.3,
Black,Std,2,0.3,
Blue,Median,77,0.001,
Blue,P25,44,0.001,
Blue,P75,88,0.001,
Blue,Mean,70,0.001,
Blue,Std,10,0.001
;;;;
run;
proc sort data=have;by Covariate pvalue;run;
proc transpose data=have out=temp;
by Covariate pvalue;
var O10;
id Statistic;
run;
data want;
 set temp;
 length median_qrange Mean_std $ 200;
 median_qrange=cats(Median,'(',P25,'-',P75,')');
 Mean_std=cats(Mean,'(',Std,')');
 keep Covariate pvalue median_qrange Mean_std;
run;


&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Apr 2016 07:35:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-and-transposing-rows/m-p/260999#M50704</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-04-04T07:35:37Z</dc:date>
    </item>
    <item>
      <title>Re: Merging and transposing rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-and-transposing-rows/m-p/261008#M50709</link>
      <description>&lt;P&gt;You are designing clinical study outputs there, you may find the examples at PHUSE helpfull:&lt;BR /&gt;&lt;A href="https://github.com/phuse-org/phuse-scripts/wiki/Standard-Script-Index" target="_blank"&gt;https://github.com/phuse-org/phuse-scripts/wiki/Standard-Script-Index&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, I would expect that the company you work for already has a macro suite designed to do these types of outputs - that will be your first port of call.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2016 08:20:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-and-transposing-rows/m-p/261008#M50709</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-04T08:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: Merging and transposing rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-and-transposing-rows/m-p/261021#M50711</link>
      <description>Thank you RW9&lt;BR /&gt;I am actually a physician doing my own stats, so I dont work for a company, but the link you gave is very useful indeed&lt;BR /&gt;Kind regards&lt;BR /&gt;AM</description>
      <pubDate>Mon, 04 Apr 2016 08:56:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-and-transposing-rows/m-p/261021#M50711</guid>
      <dc:creator>ammarhm</dc:creator>
      <dc:date>2016-04-04T08:56:28Z</dc:date>
    </item>
    <item>
      <title>Re: Merging and transposing rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-and-transposing-rows/m-p/261039#M50717</link>
      <description>&lt;P&gt;Hmm, when I run your code my WANT dataset looks like this:&lt;/P&gt;
&lt;PRE&gt;                                                                      median_
                                        Obs    Covariate    pvalue    qrange       Mean_std

                                         1       Black      0.3       4(2-5)        4(2)   
                                         2       Blue       0.001     77(44-88)     70(10) 
                                         3       Red        0.05      8(4-12)       9(3)   
                                         4       White      0.1       22(5-66)      (12)   
                                         5       White      0.1.      (-)           44()   
&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Apr 2016 10:27:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-and-transposing-rows/m-p/261039#M50717</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-04-04T10:27:17Z</dc:date>
    </item>
  </channel>
</rss>

