<?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: Error with Market Basket Analysis Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Error-with-Market-Basket-Analysis-Macro/m-p/532070#M145756</link>
    <description>Please post the full solution for future users who have the same question. I don't see where double quotes would fix it either, so curious. I was going to suggest a type mismatch, where a column from the XLSX file was imported as character instead of numeric.</description>
    <pubDate>Fri, 01 Feb 2019 16:05:07 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-02-01T16:05:07Z</dc:date>
    <item>
      <title>Error with Market Basket Analysis Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-with-Market-Basket-Analysis-Macro/m-p/531884#M145675</link>
      <description>&lt;P&gt;&lt;FONT face="lucida sans unicode,lucida sans" size="2"&gt;&lt;STRONG&gt;Error with Market Basket Analysis Macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="lucida sans unicode,lucida sans" size="3"&gt;I found this Macro online to run the Market Basket Analysis:-&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="lucida sans unicode,lucida sans" size="3"&gt;&lt;A href="https://github.com/clarioanalytics/marketbasket" target="_blank"&gt;https://github.com/clarioanalytics/marketbasket&amp;nbsp;&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="lucida sans unicode,lucida sans" size="3"&gt;The macro is related to an old SAS paper published in 2002.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="lucida sans unicode,lucida sans" size="3"&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings/proceedings/sugi28/223-28.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings/proceedings/sugi28/223-28.pdf&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="lucida sans unicode,lucida sans" size="3"&gt;I created a sample file (sample_MBA_file.xlsx and used in the used). This file&lt;/FONT&gt;&lt;FONT face="lucida sans unicode,lucida sans" size="3"&gt;&amp;nbsp;is also attached to the post.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="lucida sans unicode,lucida sans" size="3"&gt;The code is as follows:-&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*----------------------------------------------------------------------*
 *                    Market Basket Analysis Macro                      *
 * Copyright(c) 2014 by Clario Analytics, Eden Prairie, MN              *
 * Please feel free to use and modify this code in whatever manner      *
 * you deem appropriate. All Clario asks is that, in return, you share  *
 * valuable enhancements/efficiencies so that Clario can integrate and  *
 * continue sharing them.                                               *
 *----------------------------------------------------------------------*
 *  Macro Definitions:                                                  *
 *  Define lib, set, basket_dimension, and analysis_unit where 'lib'    *
 *  is the library containing the transactional dataset (use libname    *
 *  if necessary), 'set' is the transactional dataset name,             *
 *  'basket_dimension' is the unique basket dimension identifier        *
 *  (i.e. customer identifier) and 'analysis_unit' is the unique        *
 *  anlysis unit identifier (i.e. product identifier).                  *
 *----------------------------------------------------------------------*
 *  Output:                                                             *
 *  'mba_results' dataset in the defined library containing             *
 *  unfiltered affinity findings.                                       *
 *----------------------------------------------------------------------*
 *  Created:  01 Sep 2002                                               *
 *----------------------------------------------------------------------*/

/*libname libref 'library location';*/ 
libname MBA "/folders/myfolders/MBA/";
proc import datafile='/folders/myfolders/sample_MBA_file.xlsx'
dbms=xlsx replace
out=MBA.sample_MBA_file;
run;

PROC PRINT DATA=MBA.sample_MBA_file;
RUN;

%let lib = MBA;  *Library Name;
%let set = sample_MBA_file;  *Dataset Name;
%let basket_dimension = BASKET_DIMENSION;  *Basket Dimension Identifier (ie customer id);
%let analysis_unit = ANALYSIS_UNIT;  *Analysis Unit Identifier (ie product id);

*Modifications are seldom required below this point;

*Builds dataset containing distinct analysis units and basket dimension
frequencies for each;
proc sql;
	create table &amp;amp;lib..analysis_unit as
    select
    &amp;amp;analysis_unit,
    count(distinct(&amp;amp;basket_dimension)) as ANALYSIS_UNIT_FREQ
    from &amp;amp;lib..&amp;amp;set
    group by &amp;amp;analysis_unit;
quit;
*Builds dataset containing distinct basket dimensions and analysis unit
frequencies for each;
proc sql;
	create table &amp;amp;lib..basket_dimension as
    select
    &amp;amp;basket_dimension,
    count(&amp;amp;analysis_unit) as &amp;amp;basket_dimension._freq
    from &amp;amp;lib..&amp;amp;set
    group by &amp;amp;basket_dimension;
quit;

*Builds a new dataset containing only those basket dimensions with more
than one distinct analysis unit to accelerate processing;
proc sql;
	create table &amp;amp;lib..&amp;amp;set._reduced as
    select a.&amp;amp;basket_dimension, a.&amp;amp;analysis_unit
    from &amp;amp;lib..&amp;amp;set a, &amp;amp;lib..basket_dimension b
    where a.&amp;amp;basket_dimension = b.&amp;amp;basket_dimension
    and b.&amp;amp;basket_dimension._freq &amp;gt; 1;
quit;

*Creates simple indexes to accelerate processing;
proc datasets library = &amp;amp;lib;
	modify &amp;amp;set._reduced;
    index create &amp;amp;analysis_unit;
    index create &amp;amp;basket_dimension;
quit;

*Defines a macro variable containing a count of distinct basket dimensions;
%let dsid=%sysfunc(open(&amp;amp;lib..basket_dimension,i));
%let tot_basket_dimensions=%sysfunc(attrn(&amp;amp;dsid,nobs));
%let rc=%sysfunc(close(&amp;amp;dsid));
%put;
%put Count of distinct &amp;amp;basket_dimension: &amp;amp;tot_basket_dimensions;
%put;

*Defines a macro variable containing a count of distinct analysis units;
%let dsid=%sysfunc(open(&amp;amp;lib..analysis_unit,i));
%let tot_analysis_units=%sysfunc(attrn(&amp;amp;dsid,nobs));
%let rc=%sysfunc(close(&amp;amp;dsid));
%put;
%put Count of distinct &amp;amp;analysis_unit: &amp;amp;tot_analysis_units;
%put;


%macro marketbasket;
%do analysis_unit_nb = 1 %to &amp;amp;tot_analysis_units;
%*Defines macro variables containing current iteration analysis unit and analysis unit frequency;

        data _null_;
        	set &amp;amp;lib..analysis_unit;
            if _n_ = &amp;amp;analysis_unit_nb then do;
            	call symput ('curr_analysis_unit',compress(&amp;amp;analysis_unit));
            	call symput ('curr_analysis_unit_freq',ANALYSIS_UNIT_FREQ);
            end;
        run;
        
        
        %put ;%put &amp;gt;&amp;gt;&amp;gt; Working on analysis unit #&amp;amp;analysis_unit_nb (&amp;amp;curr_analysis_unit);
        options notes;
        %*Builds a new dataset containing all analysis units for basket dimensions 
		containing the current analysis unit (aka basket donors);
        proc sql;
        	create table &amp;amp;lib..basket_donors as
            select
            &amp;amp;basket_dimension, &amp;amp;analysis_unit
            from &amp;amp;lib..&amp;amp;set._reduced
            where &amp;amp;basket_dimension in(select
            &amp;amp;basket_dimension from &amp;amp;lib..&amp;amp;set._reduced
            where &amp;amp;analysis_unit = /* " */&amp;amp;curr_analysis_unit/* " */);
        quit;
        options nonotes;
        %*Counts frequency of co-occurance between the current analysis unit and 
		  all other analysis units;
        proc sql;
        	create table &amp;amp;lib..co_occurance as
            select
            &amp;amp;analysis_unit as ASSOC_ANALYSIS_UNIT,
			count(distinct(&amp;amp;basket_dimension)) as FREQ_CO_OCCUR
            from &amp;amp;lib..basket_donors
            where &amp;amp;analysis_unit ^= /*"*/&amp;amp;curr_analysis_unit/*"*/
            group by &amp;amp;analysis_unit;
        quit;
        %*Adds variables to co_occurance dataset for later affinity calculations;
        data &amp;amp;lib..co_occurance;
        	set &amp;amp;lib..co_occurance;
            ANALYSIS_UNIT_FREQ = &amp;amp;curr_analysis_unit_freq;
            TOT_BASKET_DIMENSIONS = &amp;amp;tot_basket_dimensions;
        run;
        %*Affinity calculations;
        proc sql;
            create table &amp;amp;lib..affinity_calc as
            select
            b.ASSOC_ANALYSIS_UNIT,
            b.FREQ_CO_OCCUR,
            b.TOT_BASKET_DIMENSIONS,
            b.ANALYSIS_UNIT_FREQ,
            a.ANALYSIS_UNIT_FREQ as ASSOC_ANALYSIS_UNIT_FREQ,
            (b.FREQ_CO_OCCUR/b.ANALYSIS_UNIT_FREQ) as CONFIDENCE,
            (b.FREQ_CO_OCCUR/b.TOT_BASKET_DIMENSIONS) as SUPPORT,
            ((ASSOC_ANALYSIS_UNIT_FREQ)/b.TOT_BASKET_DIMENSIONS) as EXPECTED_CONFIDENCE,
            ((calculated CONFIDENCE)/(calculated EXPECTED_CONFIDENCE)) as LIFT
            from &amp;amp;lib..analysis_unit a, &amp;amp;lib..co_occurance b
            where a.&amp;amp;analysis_unit = b.ASSOC_ANALYSIS_UNIT;
        quit;
		%*Descriptive variable added to output dataset;
        data &amp;amp;lib..affinity_calc;
            set &amp;amp;lib..affinity_calc;
        	ANALYSIS_UNIT = /*"*/&amp;amp;curr_analysis_unit/*"*/;
        run;
		%*Reorder variables and gather results;
        proc sql;
        	create table &amp;amp;lib..affinity_calc as
            select
            ANALYSIS_UNIT, ANALYSIS_UNIT_FREQ, ASSOC_ANALYSIS_UNIT, 
			ASSOC_ANALYSIS_UNIT_FREQ,
            FREQ_CO_OCCUR, TOT_BASKET_DIMENSIONS,
            SUPPORT, CONFIDENCE, EXPECTED_CONFIDENCE, LIFT
            from &amp;amp;lib..affinity_calc
            order by LIFT desc;
        quit;
		%if &amp;amp;analysis_unit_nb = 1 %then %do;
			%if %sysfunc(exist(&amp;amp;lib..mba_results)) %then %do;
				proc delete data = &amp;amp;lib..mba_results;
  				run;
			%end;
        	data &amp;amp;lib..mba_results;
            	set &amp;amp;lib..affinity_calc;
          	run;
        %end;
        %else %do;
        	data &amp;amp;lib..mba_results;
          		set &amp;amp;lib..mba_results &amp;amp;lib..affinity_calc;
        	run;
        %end;
	%end;
	proc delete data = &amp;amp;lib..analysis_unit &amp;amp;lib..basket_dimension &amp;amp;lib..&amp;amp;set._reduced
			&amp;amp;lib..basket_donors &amp;amp;lib..co_occurance &amp;amp;lib..affinity_calc;
	run;
%mend marketbasket;

%marketbasket&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;But when I run it after defining the macro variables I am getting the following error:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="sasSource"&gt;&lt;FONT color="#FF0000"&gt;&amp;gt;&amp;gt;&amp;gt; Working on analysis unit #1 (apple)&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;FONT color="#FF0000"&gt;ERROR: The following columns were not found in the contributing tables: apple.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&lt;FONT color="#FF0000"&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&lt;FONT color="#FF0000"&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&lt;FONT color="#FF0000"&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&lt;FONT color="#FF0000"&gt;real time 0.03 seconds&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&lt;FONT color="#FF0000"&gt;cpu time 0.01 seconds&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;FONT color="#FF0000"&gt;ERROR: File MBA.BASKET_DONORS.DATA does not exist.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;FONT color="#FF0000"&gt;ERROR: File MBA.CO_OCCURANCE.DATA does not exist.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasWarning"&gt;&lt;FONT color="#FF0000"&gt;WARNING: The data set MBA.CO_OCCURANCE may be incomplete. When this step was stopped there were 0 observations and 2 variables.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;FONT color="#FF0000"&gt;ERROR: Column ASSOC_ANALYSIS_UNIT could not be found in the table/view identified with the correlation name B.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;FONT color="#FF0000"&gt;ERROR: Column FREQ_CO_OCCUR could not be found in the table/view identified with the correlation name B.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;FONT color="#FF0000"&gt;ERROR: Column FREQ_CO_OCCUR could not be found in the table/view identified with the correlation name B.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;FONT color="#FF0000"&gt;ERROR: Column FREQ_CO_OCCUR could not be found in the table/view identified with the correlation name B.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;FONT color="#FF0000"&gt;ERROR: Column ASSOC_ANALYSIS_UNIT could not be found in the table/view identified with the correlation name B.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;FONT color="#FF0000"&gt;ERROR: File MBA.AFFINITY_CALC.DATA does not exist.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasWarning"&gt;&lt;FONT color="#FF0000"&gt;WARNING: The data set MBA.AFFINITY_CALC may be incomplete. When this step was stopped there were 0 observations and 2 variables.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;FONT color="#FF0000"&gt;ERROR: The following columns were not found in the contributing tables: ANALYSIS_UNIT_FREQ, ASSOC_ANALYSIS_UNIT,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;FONT color="#FF0000"&gt;ASSOC_ANALYSIS_UNIT_FREQ, CONFIDENCE, EXPECTED_CONFIDENCE, FREQ_CO_OCCUR, LIFT, SUPPORT, TOT_BASKET_DIMENSIONS.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;STRONG&gt;&lt;FONT face="lucida sans unicode,lucida sans"&gt;Please help and advise how to fix this macro, thanks!&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="lucida sans unicode,lucida sans"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 05:13:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-with-Market-Basket-Analysis-Macro/m-p/531884#M145675</guid>
      <dc:creator>rahul_wishard</dc:creator>
      <dc:date>2019-02-01T05:13:05Z</dc:date>
    </item>
    <item>
      <title>Re: Error with Market Basket Analysis Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-with-Market-Basket-Analysis-Macro/m-p/531912#M145686</link>
      <description>&lt;P&gt;Sorry, this a Q&amp;amp;A board, not here to fix third party tools.&amp;nbsp; What I would say is the error could not be clearer:&lt;/P&gt;
&lt;DIV class="sasSource"&gt;&lt;FONT color="#FF0000"&gt;&amp;gt;&amp;gt;&amp;gt; Working on analysis unit #1 (apple)&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;&lt;FONT color="#FF0000"&gt;ERROR: The following columns were not found in the contributing tables: apple.&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;&lt;FONT color="#000000"&gt;From that you start debugging each step, did the data import correctly, is that item in the data, does each step run.&amp;nbsp; When you get to the macro, turn on options symbolgen mlogic mprint; to see what is generated etc.&amp;nbsp; &amp;nbsp;Simple debugging.&lt;/FONT&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 01 Feb 2019 08:47:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-with-Market-Basket-Analysis-Macro/m-p/531912#M145686</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-02-01T08:47:17Z</dc:date>
    </item>
    <item>
      <title>Re: Error with Market Basket Analysis Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-with-Market-Basket-Analysis-Macro/m-p/531946#M145700</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;Thanks the debugging step helped! and I figured out the issue was with the macro variable within the where statement in proc sql, added a &lt;SPAN&gt;double quotes fixed the issue.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 12:18:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-with-Market-Basket-Analysis-Macro/m-p/531946#M145700</guid>
      <dc:creator>rahul_wishard</dc:creator>
      <dc:date>2019-02-01T12:18:44Z</dc:date>
    </item>
    <item>
      <title>Re: Error with Market Basket Analysis Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-with-Market-Basket-Analysis-Macro/m-p/532070#M145756</link>
      <description>Please post the full solution for future users who have the same question. I don't see where double quotes would fix it either, so curious. I was going to suggest a type mismatch, where a column from the XLSX file was imported as character instead of numeric.</description>
      <pubDate>Fri, 01 Feb 2019 16:05:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-with-Market-Basket-Analysis-Macro/m-p/532070#M145756</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-01T16:05:07Z</dc:date>
    </item>
  </channel>
</rss>

