<?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: Restructure Dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Restructure-Dataset/m-p/424934#M104643</link>
    <description>&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Post test data in the form of a datastep!!&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As such I am not typing that in.&amp;nbsp; If you have a large amount of data, it will take a large amount of time, irrespective of what code you use.&amp;nbsp; Although from your output want data I don't see how transpose could get your there unless you have multiple procs.&amp;nbsp; A datastep, which loops of an array of the variables and outputs a row for each item, then left join a count onto that, may be a bit quicker.&lt;/P&gt;</description>
    <pubDate>Thu, 04 Jan 2018 15:01:15 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-01-04T15:01:15Z</dc:date>
    <item>
      <title>Restructure Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Restructure-Dataset/m-p/424930#M104639</link>
      <description>&lt;P&gt;I have the below dataset at a customer level-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;BR /&gt;data have;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input CUSTOMER_ID : $1. Channel_R : $15. Channel_O : $15. Channel_W : $15. Brand_Brand1 : $15. Brand_Brand2 : $15.;&lt;BR /&gt;datalines; &lt;BR /&gt;1 Missing $0.01-$25 $100.01-$150 $150.01-$200 $200+&lt;BR /&gt;2 &amp;lt;$0 $25.01-$50 Missing $100.01-$150 $50.01-$75&lt;BR /&gt;3 Missing $0.01-$25 $100.01-$150 $150.01-$200 $200+&lt;BR /&gt;4 &amp;lt;$0 $25.01-$50 Missing $100.01-$150 $50.01-$75&lt;BR /&gt;5 Missing $0.01-$25 $100.01-$150 $150.01-$200 $200+&lt;BR /&gt;6 &amp;lt;$0 $25.01-$50 Missing $100.01-$150 $50.01-$75&lt;BR /&gt;7 $25.01-$50 $0.01-$25 $100.01-$150 $150.01-$200 $200+&lt;BR /&gt;8 &amp;lt;$0 $25.01-$50 $25.01-$50 $100.01-$150 $50.01-$75&lt;BR /&gt;9 Missing $0.01-$25 $100.01-$150 $150.01-$200 $200+&lt;BR /&gt;10 &amp;lt;$0 $25.01-$50 Missing $100.01-$150 $50.01-$75&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;I need the output as follows-&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input Amount : $15. Customer_Count : $5. Brand : $15. Channel : $10.;&lt;BR /&gt;datalines;&lt;BR /&gt;Missing 100 Brand1 W&lt;BR /&gt;&amp;lt;$0 200 Brand1 W&lt;BR /&gt;$.01-$25 300 Brand1 W&lt;BR /&gt;$25.01-$50 400 Brand1 W&lt;BR /&gt;$50.01-$75 500 Brand1 W&lt;BR /&gt;$75.01-$100 600 Brand1 W&lt;BR /&gt;$100.01-$150 700 Brand1 W&lt;BR /&gt;$150.01-$200 800 Brand1 W&lt;BR /&gt;$200+ 900 Brand1 W&lt;BR /&gt;Missing 100 Brand2 R&lt;BR /&gt;&amp;lt;$0 200 Brand2 R&lt;BR /&gt;$0.01-$25 300 Brand2 R&lt;BR /&gt;$25.01-$50 400 Brand2 R&lt;BR /&gt;$50.01-$75 500 Brand2 R&lt;BR /&gt;$75.01-$100 600 Brand2 R&lt;BR /&gt;$100.01-$150 700 Brand2 R&lt;BR /&gt;$150.01-$200 800 Brand2 R&lt;BR /&gt;$200+ 900 Brand2 R&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried using PROC Transpose but since the dataset is very large, it takes a huge amount of time..&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 15:27:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Restructure-Dataset/m-p/424930#M104639</guid>
      <dc:creator>sasmaverick</dc:creator>
      <dc:date>2018-01-04T15:27:41Z</dc:date>
    </item>
    <item>
      <title>Re: Restructure Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Restructure-Dataset/m-p/424934#M104643</link>
      <description>&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Post test data in the form of a datastep!!&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As such I am not typing that in.&amp;nbsp; If you have a large amount of data, it will take a large amount of time, irrespective of what code you use.&amp;nbsp; Although from your output want data I don't see how transpose could get your there unless you have multiple procs.&amp;nbsp; A datastep, which loops of an array of the variables and outputs a row for each item, then left join a count onto that, may be a bit quicker.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 15:01:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Restructure-Dataset/m-p/424934#M104643</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-01-04T15:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: Restructure Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Restructure-Dataset/m-p/424941#M104647</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;: Sorry. Below my restructured question. It's a bit challenging for me hence I was looking for a proper code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input CUSTOMER_ID : $1. Channel_R : $15. Channel_O : $15. Channel_W : $15. Brand_Brand1 : $15. Brand_Brand2 : $15.;&lt;BR /&gt;datalines; &lt;BR /&gt;1 Missing $0.01-$25 $100.01-$150 $150.01-$200 $200+&lt;BR /&gt;2 &amp;lt;$0 $25.01-$50 Missing $100.01-$150 $50.01-$75&lt;BR /&gt;3 Missing $0.01-$25 $100.01-$150 $150.01-$200 $200+&lt;BR /&gt;4 &amp;lt;$0 $25.01-$50 Missing $100.01-$150 $50.01-$75&lt;BR /&gt;5 Missing $0.01-$25 $100.01-$150 $150.01-$200 $200+&lt;BR /&gt;6 &amp;lt;$0 $25.01-$50 Missing $100.01-$150 $50.01-$75&lt;BR /&gt;7 $25.01-$50 $0.01-$25 $100.01-$150 $150.01-$200 $200+&lt;BR /&gt;8 &amp;lt;$0 $25.01-$50 $25.01-$50 $100.01-$150 $50.01-$75&lt;BR /&gt;9 Missing $0.01-$25 $100.01-$150 $150.01-$200 $200+&lt;BR /&gt;10 &amp;lt;$0 $25.01-$50 Missing $100.01-$150 $50.01-$75&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data want;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input Amount : $15. Customer_Count : $5. Brand : $15. Channel : $10.;&lt;BR /&gt;datalines;&lt;BR /&gt;Missing 100 Brand1 W&lt;BR /&gt;&amp;lt;$0 200 Brand1 W&lt;BR /&gt;$.01-$25 300 Brand1 W&lt;BR /&gt;$25.01-$50 400 Brand1 W&lt;BR /&gt;$50.01-$75 500 Brand1 W&lt;BR /&gt;$75.01-$100 600 Brand1 W&lt;BR /&gt;$100.01-$150 700 Brand1 W&lt;BR /&gt;$150.01-$200 800 Brand1 W&lt;BR /&gt;$200+ 900 Brand1 W&lt;BR /&gt;Missing 100 Brand2 R&lt;BR /&gt;&amp;lt;$0 200 Brand2 R&lt;BR /&gt;$0.01-$25 300 Brand2 R&lt;BR /&gt;$25.01-$50 400 Brand2 R&lt;BR /&gt;$50.01-$75 500 Brand2 R&lt;BR /&gt;$75.01-$100 600 Brand2 R&lt;BR /&gt;$100.01-$150 700 Brand2 R&lt;BR /&gt;$150.01-$200 800 Brand2 R&lt;BR /&gt;$200+ 900 Brand2 R&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 15:25:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Restructure-Dataset/m-p/424941#M104647</guid>
      <dc:creator>sasmaverick</dc:creator>
      <dc:date>2018-01-04T15:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: Restructure Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Restructure-Dataset/m-p/424945#M104649</link>
      <description>&lt;P&gt;Please describe what (and how as a rule) to get the "amount" for:&lt;/P&gt;
&lt;P&gt;Channel_R and Brand_Brand1&lt;/P&gt;
&lt;P&gt;Channel_R and Brand_Brand2&lt;/P&gt;
&lt;P&gt;Channel_O and Brand_Brand1&lt;/P&gt;
&lt;P&gt;Channel_O and Brand_Brand2&lt;/P&gt;
&lt;P&gt;Channel_W and Brand_Brand1&lt;/P&gt;
&lt;P&gt;Channel_W and Brand_Brand2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;from the data in your first row.&lt;/P&gt;
&lt;P&gt;I do NOT see any obvious way to accomplish that.&lt;/P&gt;
&lt;P&gt;I thought it might be possibly to generate a count data set first to count customers and transpose that set but the issue is the intersection of "channel" and "brand' to generate a single amount is not intuitively obvious to me.&lt;/P&gt;
&lt;P&gt;Also, are the values shown actually text or the display of a numeric value using a format?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 15:34:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Restructure-Dataset/m-p/424945#M104649</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-01-04T15:34:09Z</dc:date>
    </item>
    <item>
      <title>Re: Restructure Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Restructure-Dataset/m-p/424947#M104650</link>
      <description>&lt;P&gt;Sorry, only meant the Have dataset as a datastep.&amp;nbsp; Anyways, this goes someway to what you want, not sure how you get the customer_count, as it doesn't match the test data you provide, maybe clarify.&lt;/P&gt;
&lt;PRE&gt;data have;
  infile datalines;
  input CUSTOMER_ID : $1. Channel_R : $15. Channel_O : $15. Channel_W : $15. Brand_Brand1 : $15. Brand_Brand2 : $15.;
datalines; 
1 Missing $0.01-$25 $100.01-$150 $150.01-$200 $200+
2 &amp;lt;$0 $25.01-$50 Missing $100.01-$150 $50.01-$75
3 Missing $0.01-$25 $100.01-$150 $150.01-$200 $200+
4 &amp;lt;$0 $25.01-$50 Missing $100.01-$150 $50.01-$75
5 Missing $0.01-$25 $100.01-$150 $150.01-$200 $200+
6 &amp;lt;$0 $25.01-$50 Missing $100.01-$150 $50.01-$75
7 $25.01-$50 $0.01-$25 $100.01-$150 $150.01-$200 $200+
8 &amp;lt;$0 $25.01-$50 $25.01-$50 $100.01-$150 $50.01-$75
9 Missing $0.01-$25 $100.01-$150 $150.01-$200 $200+
10 &amp;lt;$0 $25.01-$50 Missing $100.01-$150 $50.01-$75
;
run;

data inter (keep=customer_id amount channel brand);
  set have;
  length amount channel brand $200;
  array channels{3} channel_r--channel_w;
  array brands{2} brand_brand1 brand_brand2;
  do j=1 to 3;
    amount=channels{j};
    channel=vname(channels{j});
    do i=1 to 2;
      brand=vname(brands{i});
      output;
    end;
  end;
run;

proc sql;
  create table WANT as 
  select  AMOUNT,
          count(distinct CUSTOMER_ID) as CUSTOMER_COUNT,
          CHANNEL,
          BRAND
  from    INTER
  group by AMOUNT,
           CHANNEL,
           BRAND;
quit;
      
&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Jan 2018 15:38:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Restructure-Dataset/m-p/424947#M104650</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-01-04T15:38:32Z</dc:date>
    </item>
    <item>
      <title>Re: Restructure Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Restructure-Dataset/m-p/424959#M104653</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;Thanks for the effort. I think this works. The customer count in output data shown was just for reference and not exact numbers that we would get. What I am trying to achieve is&amp;nbsp; to get the count of customers unique across an amount-channel-brand group. and I think your solutions addresses that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 16:10:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Restructure-Dataset/m-p/424959#M104653</guid>
      <dc:creator>sasmaverick</dc:creator>
      <dc:date>2018-01-04T16:10:54Z</dc:date>
    </item>
  </channel>
</rss>

