<?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: Multiple transaction lines to base table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multiple-transaction-lines-to-base-table/m-p/438274#M109251</link>
    <description>&lt;P&gt;Your starting data set reflects the way that data would normally be stored, and is most flexible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your intended transformation of the data is much more limited in how it can be processed.&amp;nbsp; What is your ultimate goal, that you want to do this at all?&amp;nbsp; There may be a way to get there using your original data.&amp;nbsp; Being new to SAS, your time is likely to be better spent learning how to program with the original data, instead of transforming it into a less flexible format.&lt;/P&gt;</description>
    <pubDate>Sun, 18 Feb 2018 17:08:03 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-02-18T17:08:03Z</dc:date>
    <item>
      <title>Multiple transaction lines to base table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-transaction-lines-to-base-table/m-p/438251#M109239</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I am new to sas and are trying to handle some customer data, and I'm not really sure how to do this. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;What I have:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data transactions;                      
input ID $  Week Segment $ Average Freq;       
datalines;            
1 1 Sports 500 2
1 1 PC 400 3
1 2 Sports 350 3
1 2 PC 550 3
2 1 Sports 650 2
2 1 PC 700 3
2 2 Sports 720 3
2 2 PC 250 3
;                                    
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;What I want:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data transactions2;
input ID Week1_Sports_Average Week1_PC_Average Week1_Sports_Freq 
Week1_PC_Freq
Week2_Sports_Average Week2_PC_Average Week2_Sports_Freq Week2_PC_Freq;
datalines;
1 500 400 2 3 350 550 3 3 
2 650 700 2 3 720 250 3 3
;
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;The only thing I got so far is:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; Data transactions3;
 SET transactions;
 if week=1 and Segment="Sports" then DO; 
 Week1_Sports_Freq=Freq; 
 Week1_Sports_Average=Average;
 END;
 else DO;
 Week1_Sports_Freq=0; 
 Week1_Sports_Average=0;
 END;
 run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This will be way too much work as I have a lot of weeks and more variables than just freq/avg.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Really hoping for some tips are, as I'm stucked.&lt;/P&gt;</description>
      <pubDate>Sun, 18 Feb 2018 13:13:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-transaction-lines-to-base-table/m-p/438251#M109239</guid>
      <dc:creator>AntrOsl</dc:creator>
      <dc:date>2018-02-18T13:13:37Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple transaction lines to base table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-transaction-lines-to-base-table/m-p/438252#M109240</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data transactions;                      
input ID $  Week Segment $ Average Freq;       
datalines;            
1 1 Sports 500 2
1 1 PC 400 3
1 2 Sports 350 3
1 2 PC 550 3
2 1 Sports 650 2
2 1 PC 700 3
2 2 Sports 720 3
2 2 PC 250 3
;                                    
run; 

proc sql noprint;
select distinct catt('transactions(where=(week=',week,' and segment="',segment,'") 
 rename=(average=week',week,'_',segment,'_average 
 freq=week',week,'_',segment,'_freq))') into : merge separated by ' '
 from transactions;
quit;
data want;
 merge &amp;amp;merge;
 by id;
 drop Week Segment;
run;
proc print noobs;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 18 Feb 2018 14:11:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-transaction-lines-to-base-table/m-p/438252#M109240</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-02-18T14:11:39Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple transaction lines to base table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-transaction-lines-to-base-table/m-p/438256#M109244</link>
      <description>&lt;P&gt;cool answer&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;but may have to do lot of merges, if the dataset has 1000 id's or more.&lt;/P&gt;</description>
      <pubDate>Sun, 18 Feb 2018 15:37:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-transaction-lines-to-base-table/m-p/438256#M109244</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-02-18T15:37:25Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple transaction lines to base table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-transaction-lines-to-base-table/m-p/438274#M109251</link>
      <description>&lt;P&gt;Your starting data set reflects the way that data would normally be stored, and is most flexible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your intended transformation of the data is much more limited in how it can be processed.&amp;nbsp; What is your ultimate goal, that you want to do this at all?&amp;nbsp; There may be a way to get there using your original data.&amp;nbsp; Being new to SAS, your time is likely to be better spent learning how to program with the original data, instead of transforming it into a less flexible format.&lt;/P&gt;</description>
      <pubDate>Sun, 18 Feb 2018 17:08:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-transaction-lines-to-base-table/m-p/438274#M109251</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-18T17:08:03Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple transaction lines to base table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-transaction-lines-to-base-table/m-p/438303#M109262</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data transactions;                      
input ID $  Week Segment $ Average Freq;       
datalines;            
1 1 Sports 500 2
1 1 PC 400 3
1 2 Sports 350 3
1 2 PC 550 3
2 1 Sports 650 2
2 1 PC 700 3
2 2 Sports 720 3
2 2 PC 250 3
;                                    
run; 
proc transpose data=transactions out=temp prefix=week;
by id ;
var average freq;
id  week segment;
run;

data avg(where=(_name_='Average') ) freq( where=(_name_='Freq') );
set temp;
run;

data final_want;
merge avg(drop=_name_) freq(drop=_name_ rename=(week1sports=week1sports_freq week1pc= week1pc_freq week2pc=week2pc_freq week2sports=week2sports_freq));
by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Notes:&lt;/P&gt;&lt;P&gt;1. Renaming is the only boring and verbose thing in this exercise&lt;/P&gt;&lt;P&gt;2. Renaming is required in the last step in the statement ---&amp;nbsp; &amp;nbsp; &amp;nbsp;merge avg(rename here with average suffix) freq(&lt;SPAN&gt;rename here with freq&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;suffix)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;3. For dynamic renaming, Do refer to&amp;nbsp;&lt;A href="http://support.sas.com/kb/48/674.html&amp;nbsp;" target="_blank"&gt;http://support.sas.com/kb/48/674.html&amp;nbsp;&lt;/A&gt; &amp;nbsp;for a easy copy paste that helps lazy folks like me&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Feb 2018 22:22:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-transaction-lines-to-base-table/m-p/438303#M109262</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-02-18T22:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple transaction lines to base table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-transaction-lines-to-base-table/m-p/438312#M109263</link>
      <description>&lt;P&gt;This seems even easier:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data transactions;                      
input ID $  Week Segment $ Average Freq;       
datalines;            
1 1 Sports 500 2
1 1 PC 400 3
1 2 Sports 350 3
1 2 PC 550 3
2 1 Sports 650 2
2 1 PC 700 3
2 2 Sports 720 3
2 2 PC 250 3
;                                    
run; 

data temp1;
set transactions;
temp=average;
_t1=catx('_','week'||left(week),segment,vname(average));
output;
temp=freq;
_t1=catx('_','week'||left(week),segment,vname(freq));
output;
run;

proc transpose data=temp1 out=want(drop=_name_) ;
by id ;
var temp;
id  _t1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 18 Feb 2018 23:27:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-transaction-lines-to-base-table/m-p/438312#M109263</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-02-18T23:27:03Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple transaction lines to base table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-transaction-lines-to-base-table/m-p/438363#M109286</link>
      <description>&lt;P&gt;Thank you all so much for your help. In the end I managed to do it this way:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=transactions out=tall ;
  by id week segment notsorted;
  var average freq ;
run;

data tall ;
  set tall ;
  length new_name $32 ;
  new_name = catx('_',cats('WEEK',week),segment,_name_);
run;
proc transpose data=tall out=want ;
  by id;
  id new_name;
  var col1 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Feb 2018 09:59:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-transaction-lines-to-base-table/m-p/438363#M109286</guid>
      <dc:creator>AntrOsl</dc:creator>
      <dc:date>2018-02-19T09:59:19Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple transaction lines to base table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-transaction-lines-to-base-table/m-p/439162#M109551</link>
      <description>&lt;P&gt;Not really. The factor affect the number of merging table is WEEK and the third variable.&lt;/P&gt;
&lt;P&gt;No Matter how many subject id you have, if there were only four different combination of them ,you only need merge four tables.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2018 03:53:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-transaction-lines-to-base-table/m-p/439162#M109551</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-02-22T03:53:30Z</dc:date>
    </item>
  </channel>
</rss>

