<?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: Nested Loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Nested-Loop/m-p/482822#M125132</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; gave you a good explanation of why you don't get the results&lt;/P&gt;
&lt;P&gt;you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am just curious about the following line in your code :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let pcoun = %sysfunc(countw(&amp;amp;%scan(vlist,&amp;amp;i))) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What is it exactly supposed to do ?&lt;/P&gt;</description>
    <pubDate>Tue, 31 Jul 2018 13:51:14 GMT</pubDate>
    <dc:creator>gamotte</dc:creator>
    <dc:date>2018-07-31T13:51:14Z</dc:date>
    <item>
      <title>Nested Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-Loop/m-p/482784#M125120</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have following&amp;nbsp;code;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;options mprint;&lt;BR /&gt;%let no = 1 2 3 4 5 6;&lt;BR /&gt;
%macro samples (country);&lt;BR /&gt;&lt;BR /&gt; %let pcoun = %sysfunc(countw(&amp;amp;&amp;amp;country)) ;&lt;BR /&gt; %do i = 1 %to &amp;amp;pcoun;&lt;BR /&gt; %do sta = 1 %to 3;&lt;BR /&gt;&lt;BR /&gt;proc sql outobs=2;&lt;BR /&gt;create table selected_&amp;amp;country_&amp;amp;sta_&amp;amp;i as &lt;BR /&gt;select *&lt;BR /&gt;from mntly.joined_&amp;amp;country&lt;BR /&gt;where n = &amp;amp;i and input(stage,2.) = &amp;amp;sta;&lt;BR /&gt;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;&lt;BR /&gt;%mend;&lt;BR /&gt;&lt;BR /&gt;%samples(no);&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want tables&amp;nbsp;with 2 entries for each portfolio&amp;nbsp;and each stage. it has to create 18 tables. but it only creates 3 tables and stage 2 3 with empty tables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get following log&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;26         options mprint;
27         %macro samples (country);
28         
29         	%let pcoun = %sysfunc(countw(&amp;amp;&amp;amp;country)) ;
30         		%do i = 1 %to &amp;amp;pcoun;
31         			%do sta = 1 %to 3;
32         
33         proc sql outobs=2;
34         create table selected_&amp;amp;country._&amp;amp;sta._&amp;amp;i. as
35         select *
36         from mntly.joined_&amp;amp;country
37         where n = &amp;amp;i and input(stage,2.) = &amp;amp;sta;
38         
39         %end;
40         %end;
41         
42         %mend;
43         
44         %samples(no);
MPRINT(SAMPLES):   proc sql outobs=2;
MPRINT(SAMPLES):   create table selected_no_1_1 as select * from mntly.joined_no where n = 1 and input(stage,2.) = 1;
WARNING: Statement terminated early due to OUTOBS=2 option.
NOTE: Table WORK.SELECTED_NO_1_1 created, with 2 rows and 639 columns.

NOTE: PROCEDURE SQL used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
      

MPRINT(SAMPLES):   proc sql outobs=2;
MPRINT(SAMPLES):   create table selected_no_2_1 as select * from mntly.joined_no where n = 1 and input(stage,2.) = 2;
NOTE: Table WORK.SELECTED_NO_2_1 created, with 0 rows and 639 columns.
2                                                          The SAS System                               11:43 Tuesday, July 31, 2018


NOTE: PROCEDURE SQL used (Total process time):
      real time           7.81 seconds
      cpu time            7.59 seconds
      

MPRINT(SAMPLES):   proc sql outobs=2;
MPRINT(SAMPLES):   create table selected_no_3_1 as select * from mntly.joined_no where n = 1 and input(stage,2.) = 3;
NOTE: Table WORK.SELECTED_NO_3_1 created, with 0 rows and 639 columns.

45         
46         GOPTIONS NOACCESSIBLE;
47         %LET _CLIENTTASKLABEL=;
48         %LET _CLIENTPROCESSFLOWNAME=;
49         %LET _CLIENTPROJECTPATH=;
50         %LET _CLIENTPROJECTPATHHOST=;
51         %LET _CLIENTPROJECTNAME=;
52         %LET _SASPROGRAMFILE=;
53         %LET _SASPROGRAMFILEHOST=;
54         
55         ;*';*";*/;quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           7.82 seconds
      cpu time            7.68 seconds
      
55       !                run;

56         ODS _ALL_ CLOSE;
57         
58         
59         QUIT; RUN;
60         &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jul 2018 13:40:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-Loop/m-p/482784#M125120</guid>
      <dc:creator>Myurathan</dc:creator>
      <dc:date>2018-07-31T13:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-Loop/m-p/482795#M125128</link>
      <description>&lt;P&gt;Your output dataset name is determined solely by the outermost loop, so you will get only one result from the final iteration of the inner loops. Everything else will be overwritten.&lt;/P&gt;
&lt;P&gt;You need to somehow incorporate &amp;amp;w and &amp;amp;sta into the dataset name.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jul 2018 13:08:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-Loop/m-p/482795#M125128</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-31T13:08:59Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-Loop/m-p/482798#M125129</link>
      <description>&lt;P&gt;Show us the SASLOG! Hint: Don't make us do work that SAS has already done. Hint: don't tell us it doesn't work, explain why it didn't work, what did you expect to get and what did you actually get.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Better yet, place&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as the first line of your code, run it again, and then show us the SASLOG. When you are going to paste the SASLOG into your message, click on the {i} icon first, paste the SASLOG into that window.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jul 2018 13:11:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-Loop/m-p/482798#M125129</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-07-31T13:11:10Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-Loop/m-p/482817#M125130</link>
      <description>I have followed your instruction and changed the code to run for only one country. Still, it is not producing 18 tables as I wanted. It produces only three tables and only one table with two observations.</description>
      <pubDate>Tue, 31 Jul 2018 13:42:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-Loop/m-p/482817#M125130</guid>
      <dc:creator>Myurathan</dc:creator>
      <dc:date>2018-07-31T13:42:37Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-Loop/m-p/482822#M125132</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; gave you a good explanation of why you don't get the results&lt;/P&gt;
&lt;P&gt;you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am just curious about the following line in your code :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let pcoun = %sysfunc(countw(&amp;amp;%scan(vlist,&amp;amp;i))) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What is it exactly supposed to do ?&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jul 2018 13:51:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-Loop/m-p/482822#M125132</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-07-31T13:51:14Z</dc:date>
    </item>
  </channel>
</rss>

