<?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 do multiple do-loops with %Macro on DATA-command doing Cartesian product? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-multiple-do-loops-with-Macro-on-DATA-command-doing/m-p/732906#M228385</link>
    <description>&lt;P&gt;Thank you so much, Astounding!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Simply replacing single with double quotation marks truly helped.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now the codes run perfectly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have a nice weekend,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sincerely,&amp;nbsp;&lt;/P&gt;&lt;P&gt;KS -,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 11 Apr 2021 20:37:40 GMT</pubDate>
    <dc:creator>KS99</dc:creator>
    <dc:date>2021-04-11T20:37:40Z</dc:date>
    <item>
      <title>How to do multiple do-loops with %Macro on DATA-command doing Cartesian product?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-multiple-do-loops-with-Macro-on-DATA-command-doing/m-p/732814#M228354</link>
      <description>&lt;P&gt;I am having a difficulty running the following Macro codes.&amp;nbsp;&lt;/P&gt;&lt;P&gt;First of all, I work on 126 datasets, like:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;USA_2000, USA_2001 ... USA_2017&amp;nbsp;&lt;/P&gt;&lt;P&gt;JPN_2000, JPN_2001 ... JPN_2017&amp;nbsp;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;Ind_60_2000, Ind_60_2001, ... Ind_60_2017&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;126 datasets are about 7 regions over 2000~2017.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, my codes runs as follows:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%LET var1=USA;&lt;BR /&gt;%LET var2=JPN;&lt;BR /&gt;%LET var3=GBR;&lt;BR /&gt;%LET var4=Ind_73;&lt;BR /&gt;%LET var5=Ind_36;&lt;BR /&gt;%LET var6=Ind_28;&lt;BR /&gt;%LET var7=Ind_60;&lt;/P&gt;&lt;P&gt;%MACRO Onemode_network;&lt;BR /&gt;%DO i=1 %TO 1;&lt;BR /&gt;%DO j=2000 %TO 2017;&lt;BR /&gt;DATA &amp;amp;&amp;amp;var&amp;amp;i.._&amp;amp;j (drop=rc);&lt;BR /&gt;set &amp;amp;&amp;amp;var&amp;amp;i.._&amp;amp;j (rename=(source=source1))&lt;BR /&gt;&amp;amp;&amp;amp;var&amp;amp;i.._&amp;amp;j (obs=0 rename=(source=target1));&lt;BR /&gt;if _n_=1 then do;&lt;BR /&gt;declare hash h (dataset:'&amp;amp;&amp;amp;var&amp;amp;i.._&amp;amp;j (rename=(source=target1))',multidata:'y');&lt;BR /&gt;h.definekey('target');&lt;BR /&gt;h.definedata('target1');&lt;BR /&gt;h.definedone(); end;&lt;BR /&gt;do rc=h.find() by 0 until (h.find_next()^=0);&lt;BR /&gt;if source1&amp;lt;target1 then output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;%END;&lt;BR /&gt;%END;&lt;BR /&gt;%MEND Onemode_network;&lt;/P&gt;&lt;P&gt;%Onemode_network;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run them, I keep getting the following errors,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Invalid data set name at line 2 column 38.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What am I doing wrong with here? Since my codes are a patchwork from my questions and answers from multiple experts,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't see the internal logic in codes.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks in advance!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;KS -,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Apr 2021 05:15:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-multiple-do-loops-with-Macro-on-DATA-command-doing/m-p/732814#M228354</guid>
      <dc:creator>KS99</dc:creator>
      <dc:date>2021-04-11T05:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to do multiple do-loops with %Macro on DATA-command doing Cartesian product?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-multiple-do-loops-with-Macro-on-DATA-command-doing/m-p/732815#M228355</link>
      <description>&lt;P&gt;First and foremost.. What is your goal here? There is certainly a better way and we'll find it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Apr 2021 05:56:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-multiple-do-loops-with-Macro-on-DATA-command-doing/m-p/732815#M228355</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-04-11T05:56:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to do multiple do-loops with %Macro on DATA-command doing Cartesian product?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-multiple-do-loops-with-Macro-on-DATA-command-doing/m-p/732840#M228366</link>
      <description>&lt;P&gt;I think you should first specify the&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint mlogic;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to find out where the problem is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, if all 126 datasets are in the WORK library and there are no other datasets in the WORK library,&lt;/P&gt;
&lt;P&gt;the looping process will be easier if you use sashelp.vstable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set sashelp.vstable;
  where libname='WORK';
  call symputx(cats('var',_n_),memname);
  call symputx('obs',_n_);
run;

%MACRO Onemode_network;
  %do i=1 %to &amp;amp;nobs;

  DATA &amp;amp;&amp;amp;var&amp;amp;i.._&amp;amp;j (drop=rc);
/* processing... */
  run;

  %end;
%MEND Onemode_network;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 11 Apr 2021 09:52:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-multiple-do-loops-with-Macro-on-DATA-command-doing/m-p/732840#M228366</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-04-11T09:52:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to do multiple do-loops with %Macro on DATA-command doing Cartesian product?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-multiple-do-loops-with-Macro-on-DATA-command-doing/m-p/732852#M228370</link>
      <description>&lt;P&gt;I'm not sure if this will fix everything, since it's hard to relate to the error message referring to line 2.&amp;nbsp; But this definitely needs to be fixed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;References to macro variables in single quotes do not get resolved.&amp;nbsp; This line is incorrect:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(dataset:'&amp;amp;&amp;amp;var&amp;amp;i.._&amp;amp;j (rename=(source=target1))',multidata:'y');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;At a minimum, this needs to switch to double quotes to permit macro references to resolve:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(dataset:"&amp;amp;&amp;amp;var&amp;amp;i.._&amp;amp;j (rename=(source=target1))",multidata:'y');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So start by correcting the known error, and we'll see whether any problems remain.&lt;/P&gt;</description>
      <pubDate>Sun, 11 Apr 2021 13:37:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-multiple-do-loops-with-Macro-on-DATA-command-doing/m-p/732852#M228370</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-04-11T13:37:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to do multiple do-loops with %Macro on DATA-command doing Cartesian product?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-multiple-do-loops-with-Macro-on-DATA-command-doing/m-p/732904#M228383</link>
      <description>&lt;P&gt;Thank you for your kind interest in my problems!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the past, I obtained a set of codes from a SAS expert here&lt;/P&gt;&lt;P&gt;concerning how to create all the possible pair combinations (Cartesian product) for observations by each group.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The context is as follows:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800080"&gt;Hi, I need your help!&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800080"&gt;Suppose I have the following dataset,&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800080"&gt;data Network;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800080"&gt;input&amp;nbsp; Cusip&amp;nbsp; Analyst;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800080"&gt;cards;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800080"&gt;1&amp;nbsp; 1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800080"&gt;1&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800080"&gt;1&amp;nbsp; 3&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800080"&gt;2&amp;nbsp; 8&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800080"&gt;2&amp;nbsp; 9&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800080"&gt;2&amp;nbsp; 10&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800080"&gt;2&amp;nbsp; 11&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800080"&gt;2&amp;nbsp; 12&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800080"&gt;3&amp;nbsp; 45&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800080"&gt;3&amp;nbsp; 46&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800080"&gt;;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800080"&gt;run;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800080"&gt;I want to create a new dataset that looks like below,&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800080"&gt;__________________________&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800080"&gt;Cusip Var1 Var2&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800080"&gt;1&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; 2&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800080"&gt;1&amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; 3&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800080"&gt;1&amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; 1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800080"&gt;2&amp;nbsp; &amp;nbsp;8&amp;nbsp; &amp;nbsp; 9&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800080"&gt;2&amp;nbsp; &amp;nbsp;9&amp;nbsp; 10&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800080"&gt;2 10&amp;nbsp; 11&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800080"&gt;2 11&amp;nbsp; 12&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800080"&gt;2 12&amp;nbsp; &amp;nbsp; 8&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800080"&gt;2&amp;nbsp; &amp;nbsp;8&amp;nbsp; &amp;nbsp;11&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800080"&gt;2&amp;nbsp; &amp;nbsp;8&amp;nbsp; &amp;nbsp;10&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800080"&gt;2&amp;nbsp; &amp;nbsp;9&amp;nbsp; &amp;nbsp;12&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800080"&gt;2&amp;nbsp; &amp;nbsp;9&amp;nbsp; &amp;nbsp;11&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800080"&gt;2&amp;nbsp; 10&amp;nbsp; 12&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800080"&gt;3&amp;nbsp; 45&amp;nbsp; 46&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800080"&gt;________________________&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800080"&gt;In other words, I want to create nC2 for each Cusip.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800080"&gt;I tried using Cartesian production (full merging), but cleaning the duplicates again throws me into the mire.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800080"&gt;Many thanks, in advance! Sincerely,&amp;nbsp; KS -,&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;The answer code that I got was the following:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data want (drop=rc);
  set network (rename=(analyst=var1)) network (obs=0 rename=(analyst=var2));

  if _n_=1 then do;
    declare hash h (dataset:'network (rename=(analyst=var2))',multidata:'y');
      h.definekey('cusip');
      h.definedata('var2');
      h.definedone();
  end;
  do rc=h.find() by 0 until (h.find_next()^=0);
    if var1&amp;lt;var2 then output;
  end;
run&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I was going to run this code over multiple datasets.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry that my first post didn't explain things clearly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway, the problem is solved by simple replacing single quotation by double quotation marks within Macro.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sincerely,&amp;nbsp;&lt;/P&gt;&lt;P&gt;KS -,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Apr 2021 20:33:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-multiple-do-loops-with-Macro-on-DATA-command-doing/m-p/732904#M228383</guid>
      <dc:creator>KS99</dc:creator>
      <dc:date>2021-04-11T20:33:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to do multiple do-loops with %Macro on DATA-command doing Cartesian product?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-multiple-do-loops-with-Macro-on-DATA-command-doing/m-p/732905#M228384</link>
      <description>&lt;P&gt;Thank you very much for letting me know sashelp.vstable !&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will use it for my future work,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sincerely,&amp;nbsp;&lt;/P&gt;&lt;P&gt;KS -,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Apr 2021 20:36:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-multiple-do-loops-with-Macro-on-DATA-command-doing/m-p/732905#M228384</guid>
      <dc:creator>KS99</dc:creator>
      <dc:date>2021-04-11T20:36:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to do multiple do-loops with %Macro on DATA-command doing Cartesian product?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-multiple-do-loops-with-Macro-on-DATA-command-doing/m-p/732906#M228385</link>
      <description>&lt;P&gt;Thank you so much, Astounding!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Simply replacing single with double quotation marks truly helped.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now the codes run perfectly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have a nice weekend,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sincerely,&amp;nbsp;&lt;/P&gt;&lt;P&gt;KS -,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Apr 2021 20:37:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-multiple-do-loops-with-Macro-on-DATA-command-doing/m-p/732906#M228385</guid>
      <dc:creator>KS99</dc:creator>
      <dc:date>2021-04-11T20:37:40Z</dc:date>
    </item>
  </channel>
</rss>

