<?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 transfer multiple rows to single row per id_record? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/943981#M369931</link>
    <description>&lt;P&gt;From the long dataset I proposed, you need one query:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    record_id,
    sum(case when event="pre_arm" then col1 else 0 end) as pre_sum,
    sum(case when event = "post_arm" then col1 else 0 end) as post_sum,
    calculated post_sum - calculated pre_sum as diff
  from long
  group by record_id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 15 Sep 2024 13:05:45 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2024-09-15T13:05:45Z</dc:date>
    <item>
      <title>How to transfer multiple rows to single row per id_record?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/943932#M369915</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;Many thanks to help me to transfer the below design to the expected design.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;record_id&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;event&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Q1……..&amp;nbsp; Q24&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;base&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;pre_arm&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;post_arm&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; base&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pre_arm&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; post_arm&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;20&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;base&lt;/P&gt;
&lt;P&gt;20&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;pre_arm&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;20&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;post_arm&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Expected design:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;record_id &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;event&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b_Q1……..b_Q24&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;event&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;pre_Q1……..pre_Q24&amp;nbsp;&amp;nbsp; &amp;nbsp;event &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;post_Q1……..post_Q24 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; base&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;pre_arm&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; post_arm&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;20&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think it is not only proc transpose, not sure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Sep 2024 03:49:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/943932#M369915</guid>
      <dc:creator>bhr-q</dc:creator>
      <dc:date>2024-09-14T03:49:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to transfer multiple rows to single row per id_record?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/943936#M369918</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input record_id           event     $    Q1 $  Q2 $;                    
cards;
1                           base        1     1                                                   
1                           pre_arm      2     2                                        
1                           post_arm     3  3
2                          base          3  3
2                          pre_arm        2     2                       
2                          post_arm       1   1
;

proc sql noprint;
select distinct catt('have(where=(record_id=',record_id,' and event_',event,'="',event,'")
 rename=(event=event_',event,' Q1=',event,'_Q1 Q2=',event,'_Q2))') into :merge separated by ' '
 from have;
quit;
data want;
 merge &amp;amp;merge.;
 by record_id;
run;



&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 14 Sep 2024 06:19:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/943936#M369918</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-09-14T06:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to transfer multiple rows to single row per id_record?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/943944#M369922</link>
      <description>&lt;P&gt;Data in long form is almost always preferable to data in wide format.&amp;nbsp; Preferable because almost all SAS PROCs are designed to work on long data sets. So, how to do this? Don't do it, not only is that easier but you will be better off. &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 19&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What possible benefit is there of this wide format that you want compared to the long format? What is the next step in your work, is it some sort of data analysis, plotting, graphings, creating a table? Please tell us in detail so we can best advise you.&lt;/P&gt;</description>
      <pubDate>Sat, 14 Sep 2024 11:11:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/943944#M369922</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-09-14T11:11:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to transfer multiple rows to single row per id_record?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/943948#M369924</link>
      <description>&lt;P&gt;PROC TRANSPOSE will work.&amp;nbsp; You might need to run it twice however.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=tall;
  by id event;
  var q1-q24;
run;
proc transpose data=tall out=want(drop=_name_);
  by id;
  id event _name_;
  var col1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could leave the data as it is and just PRINT it that way using PROC REPORT.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=have;
   column id event,(q1-q4);
   define id / group;
   define event / across;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 14 Sep 2024 12:02:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/943948#M369924</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-09-14T12:02:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to transfer multiple rows to single row per id_record?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/943953#M369926</link>
      <description>&lt;P&gt;I'd go one step further and make your initial dataset longer:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=long name=quarter;
by record_id event notsorted;
var q:;
run;

proc report data=long;
column record_id event,quarter,col1;
define record_id / group;
define event / "" across;
define quarter / "" across;
define col1 / "" analysis;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 14 Sep 2024 16:09:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/943953#M369926</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-09-14T16:09:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to transfer multiple rows to single row per id_record?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/943966#M369927</link>
      <description>&lt;P&gt;Thank you for your help; this is a survey questionnaire with a Likert scale. I wanted to run the Wilcoxson sign rank test using proc univariate to do a few comparisons, such as comparing pre_arm &amp;nbsp;with post_arm.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the first design, if I create a column named total, which is the Sum(of Q1-Q24) for each patient_id, then how do I calculate &amp;nbsp;(total score of post_arm – total score of pre_arm) for each id to place that in proc univariate?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but with the second design, I can create two columns named a total of pre_arm, which is Sum(of preQ1-preQ24), and a total of post_arm, which is Sum(of postQ1-postQ24), then calculate the difference b/n these measures to place that in proc univariate. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems that there would be easier way with long format, is n’t it?&lt;/P&gt;</description>
      <pubDate>Sun, 15 Sep 2024 03:00:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/943966#M369927</guid>
      <dc:creator>bhr-q</dc:creator>
      <dc:date>2024-09-15T03:00:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to transfer multiple rows to single row per id_record?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/943967#M369928</link>
      <description>Thank you for your answer, it was helpful.</description>
      <pubDate>Sun, 15 Sep 2024 03:02:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/943967#M369928</guid>
      <dc:creator>bhr-q</dc:creator>
      <dc:date>2024-09-15T03:02:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to transfer multiple rows to single row per id_record?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/943968#M369929</link>
      <description>Thank you for your answer, it was helpful</description>
      <pubDate>Sun, 15 Sep 2024 03:02:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/943968#M369929</guid>
      <dc:creator>bhr-q</dc:creator>
      <dc:date>2024-09-15T03:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to transfer multiple rows to single row per id_record?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/943981#M369931</link>
      <description>&lt;P&gt;From the long dataset I proposed, you need one query:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    record_id,
    sum(case when event="pre_arm" then col1 else 0 end) as pre_sum,
    sum(case when event = "post_arm" then col1 else 0 end) as post_sum,
    calculated post_sum - calculated pre_sum as diff
  from long
  group by record_id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 15 Sep 2024 13:05:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/943981#M369931</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-09-15T13:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to transfer multiple rows to single row per id_record?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/944007#M369933</link>
      <description>&lt;P&gt;Note that the example provided in the online documentation of Proc NPAR1WAY for an exact two-sample test uses a long data set with the Class variable using the two levels.&lt;/P&gt;
&lt;P&gt;So to perform such a test on your example data;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
input record_id           event     $    Q1   Q2 ;                    
cards;
1                           base        1     1                                                   
1                           pre_arm      2     2                                        
1                           post_arm     3  3
2                          base          3  3
2                          pre_arm        2     2                       
2                          post_arm       1   1
;

proc npar1way data=have;
   where event in ('pre_arm' 'post_arm');
   class event;
   var q1 q2;
   exact wilcoxon;
run;&lt;/PRE&gt;
&lt;P&gt;The WHERE statement reduces it to two levels, as stated in your desire.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Sep 2024 21:02:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/944007#M369933</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-09-15T21:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to transfer multiple rows to single row per id_record?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/944008#M369934</link>
      <description>Thanks so much for your help.</description>
      <pubDate>Sun, 15 Sep 2024 21:10:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/944008#M369934</guid>
      <dc:creator>bhr-q</dc:creator>
      <dc:date>2024-09-15T21:10:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to transfer multiple rows to single row per id_record?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/944009#M369935</link>
      <description>&lt;P&gt;Thanks for your answer, I think before doing any stat test, even proc npar1way, need to calculate the total score &lt;STRONG&gt;in my first design&lt;/STRONG&gt;, and I created that like &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
set have;
if  event = "pre_arm" then  total_w=Sum(of &amp;amp;Q1-Q24);
if  event= "post_arm" then  total_g=Sum(of &amp;amp;Q1-Q24);&lt;BR /&gt;run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then,&amp;nbsp; there would be two columns like the below, due to this missing,&amp;nbsp; proc npar1way doesn’t work here&lt;/P&gt;
&lt;P&gt;&amp;nbsp; event&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; total_w&amp;nbsp;&amp;nbsp; total_g&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;pre_arm&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;/P&gt;
&lt;P&gt;post_arm&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;/P&gt;
&lt;P&gt;pre_arm&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Sep 2024 21:35:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/944009#M369935</guid>
      <dc:creator>bhr-q</dc:creator>
      <dc:date>2024-09-15T21:35:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to transfer multiple rows to single row per id_record?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/944012#M369936</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/465427"&gt;@bhr-q&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your answer, I think before doing any stat test, even proc npar1way, need to calculate the total score &lt;STRONG&gt;in my first design&lt;/STRONG&gt;, and I created that like &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
set have;
if  event = "pre_arm" then  total_w=Sum(of &amp;amp;Q1-Q24);
if  event= "post_arm" then  total_g=Sum(of &amp;amp;Q1-Q24);&lt;BR /&gt;run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then,&amp;nbsp; there would be two columns like the below, due to this missing,&amp;nbsp; proc npar1way doesn’t work here&lt;/P&gt;
&lt;P&gt;&amp;nbsp; event&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; total_w&amp;nbsp;&amp;nbsp; total_g&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;pre_arm&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;/P&gt;
&lt;P&gt;post_arm&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;/P&gt;
&lt;P&gt;pre_arm&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not sure what you are saying but if you just make ONE variable with the total it should work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  total=sum(of Q1-Q24);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do not overwrite your input dataset (you might lose information and have to remake if you made a logic error).&lt;/P&gt;
&lt;P&gt;The &amp;amp; in your code should not be there.&amp;nbsp; That would cause the macro processor to look for a macro variable named Q1 to expand before passing the resulting statement on to SAS to add to the data step.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Sep 2024 23:54:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/944012#M369936</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-09-15T23:54:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to transfer multiple rows to single row per id_record?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/944017#M369938</link>
      <description>&lt;P&gt;&lt;SPAN&gt;One variable is correct, but the proc npar1way that you proposed needs two variables, and I believe proc npar1way doesn't work here.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2024 00:56:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/944017#M369938</guid>
      <dc:creator>bhr-q</dc:creator>
      <dc:date>2024-09-16T00:56:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to transfer multiple rows to single row per id_record?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/944020#M369939</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/465427"&gt;@bhr-q&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN&gt;One variable is correct, but the proc npar1way that you proposed needs two variables, and I believe proc npar1way doesn't work here.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Huh.&amp;nbsp; You have two variables.&amp;nbsp; TOTAL is the numeric variable to use the VAR statement.&amp;nbsp; The other is variable that has two values to use the CLASS statement.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.stat.purdue.edu/~tqin/system101/method/method_wilcoxon_rank_sum_sas.htm" target="_blank"&gt;https://www.stat.purdue.edu/~tqin/system101/method/method_wilcoxon_rank_sum_sas.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2024 02:54:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/944020#M369939</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-09-16T02:54:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to transfer multiple rows to single row per id_record?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/944021#M369940</link>
      <description>&lt;P&gt;I know I have two variables, but with the first design, as I show above , proc npar1way doesn't work here.&lt;/P&gt;
&lt;P&gt;my design is a Wilcoxson sign rank test&amp;nbsp; not Wilcoxson rank sum test.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2024 03:02:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/944021#M369940</guid>
      <dc:creator>bhr-q</dc:creator>
      <dc:date>2024-09-16T03:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to transfer multiple rows to single row per id_record?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/944024#M369943</link>
      <description>You proposed a great way, using proc transpose twice, and you also proposed there would be another way, which is using the first design in my first comment and going for proc npar1way, but the latter is not possible.</description>
      <pubDate>Mon, 16 Sep 2024 03:16:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/944024#M369943</guid>
      <dc:creator>bhr-q</dc:creator>
      <dc:date>2024-09-16T03:16:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to transfer multiple rows to single row per id_record?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/944059#M369953</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/465427"&gt;@bhr-q&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you for your help; this is a survey questionnaire with a Likert scale. I wanted to run the Wilcoxson sign rank test using proc univariate to do a few comparisons, such as comparing pre_arm &amp;nbsp;with post_arm.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the first design, if I create a column named total, which is the Sum(of Q1-Q24) for each patient_id, then how do I calculate &amp;nbsp;(total score of post_arm – total score of pre_arm) for each id to place that in proc univariate?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but with the second design, I can create two columns named a total of pre_arm, which is Sum(of preQ1-preQ24), and a total of post_arm, which is Sum(of postQ1-postQ24), then calculate the difference b/n these measures to place that in proc univariate. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems that there would be easier way with long format, is n’t it?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is good information. It should be in your original post, otherwise we have to guess why you are doing this confusing transformation. Without knowing this, we can't provide good answers. Anyway,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;(and possibly others) have shown how to do this with long data set, and no one could have provided the way to do this with the information in your original post.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2024 12:26:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/944059#M369953</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-09-16T12:26:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to transfer multiple rows to single row per id_record?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/944060#M369954</link>
      <description>Thanks all of you for your help, much appreciated.</description>
      <pubDate>Mon, 16 Sep 2024 12:18:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transfer-multiple-rows-to-single-row-per-id-record/m-p/944060#M369954</guid>
      <dc:creator>bhr-q</dc:creator>
      <dc:date>2024-09-16T12:18:10Z</dc:date>
    </item>
  </channel>
</rss>

