<?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: Need help on how to iterate through a list of items and create a variable on custom defined bund in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-help-on-how-to-iterate-through-a-list-of-items-and-create-a/m-p/408519#M99748</link>
    <description>&lt;P&gt;Hi Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your response. Here's the code of a sample dataset:&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;
input orderid $5. product $20. bundle $2.;
datalines;
1234,1
1234,2
1232,5
;
run;
 
data want;
input orderid $5. product $20. bundle $2.;
datalines;
1234,1,1
1234,2,1
1232,5,0
;
run;
 &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the above those lines where product = 1 and product = 2 beside the same order number would have bundle = 1?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does that make sense?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Jordan&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, 30 Oct 2017 08:50:39 GMT</pubDate>
    <dc:creator>JordanWillis</dc:creator>
    <dc:date>2017-10-30T08:50:39Z</dc:date>
    <item>
      <title>Need help on how to iterate through a list of items and create a variable on custom defined bundles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-on-how-to-iterate-through-a-list-of-items-and-create-a/m-p/407968#M99472</link>
      <description>&lt;P&gt;HI All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset which has sold items in seperate lines against the same order number. I want to write a script which will look for "bundles" or groups of items and then create a variable with a 1 in it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;got&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Order no.-Item -Bundle A&lt;/P&gt;&lt;P&gt;12312&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01&amp;nbsp;&lt;/P&gt;&lt;P&gt;12312&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the above I would want bundle A to be 1 based on the criteria that an order contains a certain combination of items.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know there is a way to transpose the data but I'm sure you can loop the dataset instead?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks guys&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 10:28:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-on-how-to-iterate-through-a-list-of-items-and-create-a/m-p/407968#M99472</guid>
      <dc:creator>JordanWillis</dc:creator>
      <dc:date>2017-10-27T10:28:31Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on how to iterate through a list of items and create a variable on custom defined bund</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-on-how-to-iterate-through-a-list-of-items-and-create-a/m-p/407976#M99474</link>
      <description>&lt;P&gt;Please post your example data in a way that makes it recognizable as a SAS dataset.&lt;/P&gt;
&lt;P&gt;no.-Item and -Bundle both are invalid as SAS names.&lt;/P&gt;
&lt;P&gt;So take the macro from&amp;nbsp;&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; to convert your dataset to a datastep and post that here according to &lt;A href="https://communities.sas.com/t5/help/faqpage/faq-category-id/posting?nobounce" target="_blank"&gt;https://communities.sas.com/t5/help/faqpage/faq-category-id/posting?nobounce&lt;/A&gt;, "How can I add SAS syntax to a post? "&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 11:15:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-on-how-to-iterate-through-a-list-of-items-and-create-a/m-p/407976#M99474</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-27T11:15:08Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on how to iterate through a list of items and create a variable on custom defined bund</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-on-how-to-iterate-through-a-list-of-items-and-create-a/m-p/408519#M99748</link>
      <description>&lt;P&gt;Hi Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your response. Here's the code of a sample dataset:&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;
input orderid $5. product $20. bundle $2.;
datalines;
1234,1
1234,2
1232,5
;
run;
 
data want;
input orderid $5. product $20. bundle $2.;
datalines;
1234,1,1
1234,2,1
1232,5,0
;
run;
 &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the above those lines where product = 1 and product = 2 beside the same order number would have bundle = 1?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does that make sense?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Jordan&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, 30 Oct 2017 08:50:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-on-how-to-iterate-through-a-list-of-items-and-create-a/m-p/408519#M99748</guid>
      <dc:creator>JordanWillis</dc:creator>
      <dc:date>2017-10-30T08:50:39Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on how to iterate through a list of items and create a variable on custom defined bund</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-on-how-to-iterate-through-a-list-of-items-and-create-a/m-p/408528#M99751</link>
      <description>&lt;P&gt;I have two suggestions, one with a proc sql and a subquery, the other with proc freq and a datastep merge back:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dlm=',';
input orderid :$5. product :$20.;
datalines;
1234,1
1234,2
1232,5
;
run;

proc sql;
create table want as
select
  a.*,
  case
    when (select count(distinct b.product) from have b where b.orderid = a.orderid) &amp;gt; 1
    then '1'
    else '0'
  end as bundle
from have a
;
quit;

proc freq data=have noprint;
tables orderid /out=want1 (keep=orderid count);
run;

proc sort data=have;
by orderid;
run;

data want2;
merge
  have
  want1
;
by orderid;
if count &amp;gt; 1
then bundle = '1';
else bundle = '0';
bundle_num = count &amp;gt; 1;
drop count;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Unsing a numeric flag variable makes later use in conditions easier (0 or . = false, everything else = true)&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 09:11:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-on-how-to-iterate-through-a-list-of-items-and-create-a/m-p/408528#M99751</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-30T09:11:02Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on how to iterate through a list of items and create a variable on custom defined bund</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-on-how-to-iterate-through-a-list-of-items-and-create-a/m-p/408532#M99753</link>
      <description>&lt;P&gt;Hi Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some great examples there. I'm afraid I'm going to throw in a curve ball; what if my product ID variable is character so we can't work with the numerical logic. For example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input orderid $5. product $20. bundle $2.;
datalines;
1234 1-01
1233 2-02
1232 5
;
run;

data want;
input orderid $5. product $20. bundle $2.;
datalines;
1234 1-01 1
1233 2-02 1
1232 5-01 0
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Oct 2017 09:20:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-on-how-to-iterate-through-a-list-of-items-and-create-a/m-p/408532#M99753</guid>
      <dc:creator>JordanWillis</dc:creator>
      <dc:date>2017-10-30T09:20:42Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on how to iterate through a list of items and create a variable on custom defined bund</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-on-how-to-iterate-through-a-list-of-items-and-create-a/m-p/408537#M99754</link>
      <description>&lt;P&gt;Look at the codes again. product was already character, and both methods make no assumptions for data types.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 09:41:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-on-how-to-iterate-through-a-list-of-items-and-create-a/m-p/408537#M99754</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-30T09:41:08Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on how to iterate through a list of items and create a variable on custom defined bund</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-on-how-to-iterate-through-a-list-of-items-and-create-a/m-p/408539#M99755</link>
      <description>&lt;P&gt;So it does; All Hail Kurt!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your expert help, incredibly appreciated&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 09:43:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-on-how-to-iterate-through-a-list-of-items-and-create-a/m-p/408539#M99755</guid>
      <dc:creator>JordanWillis</dc:creator>
      <dc:date>2017-10-30T09:43:02Z</dc:date>
    </item>
  </channel>
</rss>

