<?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 Convert Array And Do while to SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-Array-And-Do-while-to-SQL/m-p/816081#M322076</link>
    <description>&lt;P&gt;I'm unable to understand the following code which was written by other programmer. Can someone help me understand this code in simple words and also I'd like to know if this can be converted to Proc SQL?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DATA ATT(DROP=J);*(DROP=FCST:);
  MERGE INVENT(IN=I)
        FCST_WIDE(IN=F);
  BY LOC MATERIAL;
  
  NEW_HAND = COALESCE(HAND,0);
  J=1;
  IF FIRST.MATERIAL THEN 
  DO;
    ARRAY FCT(*) &amp;amp;FCST_D2.;
  END;
  
  DO WHILE (NEW_HAND &amp;gt;0 and J &amp;lt;= DIM(FCT));
    
    FCT[J] = COALESCE(FCT[J],0);
    
    IF INPUT(SUBSTR(VNAME(FCT[J]),5),mmddyy10.)&amp;lt;=STOPSHIP_DT THEN 
    DO;
      
      IF NEW_HAND &amp;gt; FCT[J] THEN 
      DO;
        NEW_HAND = NEW_HAND-FCT[J];
        FCT[J]=0;
      END;
      ELSE IF FCT[J] &amp;gt; NEW_HAND THEN 
      DO;
        FCT[J] = FCT[J]-NEW_HAND;
        NEW_HAND=0;
      END;
      ELSE 
      DO;
        FCT[J]=0;
        NEW_HAND=0;
      END;
    END;
    J+1;
  END;
  
  IF LAST.MATERIAL THEN
  DO;
    REM_DEMAND = SUM(of FCST:);
  END;
RUN;


&lt;/PRE&gt;</description>
    <pubDate>Wed, 01 Jun 2022 18:11:13 GMT</pubDate>
    <dc:creator>David_Billa</dc:creator>
    <dc:date>2022-06-01T18:11:13Z</dc:date>
    <item>
      <title>Convert Array And Do while to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Array-And-Do-while-to-SQL/m-p/816081#M322076</link>
      <description>&lt;P&gt;I'm unable to understand the following code which was written by other programmer. Can someone help me understand this code in simple words and also I'd like to know if this can be converted to Proc SQL?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DATA ATT(DROP=J);*(DROP=FCST:);
  MERGE INVENT(IN=I)
        FCST_WIDE(IN=F);
  BY LOC MATERIAL;
  
  NEW_HAND = COALESCE(HAND,0);
  J=1;
  IF FIRST.MATERIAL THEN 
  DO;
    ARRAY FCT(*) &amp;amp;FCST_D2.;
  END;
  
  DO WHILE (NEW_HAND &amp;gt;0 and J &amp;lt;= DIM(FCT));
    
    FCT[J] = COALESCE(FCT[J],0);
    
    IF INPUT(SUBSTR(VNAME(FCT[J]),5),mmddyy10.)&amp;lt;=STOPSHIP_DT THEN 
    DO;
      
      IF NEW_HAND &amp;gt; FCT[J] THEN 
      DO;
        NEW_HAND = NEW_HAND-FCT[J];
        FCT[J]=0;
      END;
      ELSE IF FCT[J] &amp;gt; NEW_HAND THEN 
      DO;
        FCT[J] = FCT[J]-NEW_HAND;
        NEW_HAND=0;
      END;
      ELSE 
      DO;
        FCT[J]=0;
        NEW_HAND=0;
      END;
    END;
    J+1;
  END;
  
  IF LAST.MATERIAL THEN
  DO;
    REM_DEMAND = SUM(of FCST:);
  END;
RUN;


&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Jun 2022 18:11:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Array-And-Do-while-to-SQL/m-p/816081#M322076</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2022-06-01T18:11:13Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Array And Do while to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Array-And-Do-while-to-SQL/m-p/816085#M322078</link>
      <description>&lt;P&gt;Which part(s) do you not understand? Without data, such as which variable(s) come from which data set(s) it can be a tad misleading to guess exactly. Especially since there is a macro variable without a definition apparently providing variable names.&lt;/P&gt;
&lt;P&gt;If you have data look at the start and end result. That should help a lot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ARRAY and SQL not going to happen. You have to explicitly code every thing for each variable. Since the attached code uses BY group processing to start/stop and summarize with First. and Last. processing, which requires processing records in a specific order, not to mention the way MERGE might differ from any type of SQL join then unless you have a great deal of time.&lt;/P&gt;
&lt;P&gt;Apparently the data violates the best practice of not putting data in the variable names as there is a bit that is pulling date information from the variable names.&lt;/P&gt;
&lt;P&gt;Since the data has data inside variable names it may be possible to extract that date information so that you have Date and value pairs and completely restructure the source data sets to a more normalized form and then join the data. Maybe. That would then allow possibly allow a join on dates as well as the LOC and Material variables. Again maybe.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2022 18:27:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Array-And-Do-while-to-SQL/m-p/816085#M322078</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-01T18:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Array And Do while to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Array-And-Do-while-to-SQL/m-p/816086#M322079</link>
      <description>I'd like to understand array part and do while loop&lt;BR /&gt;</description>
      <pubDate>Wed, 01 Jun 2022 18:33:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Array-And-Do-while-to-SQL/m-p/816086#M322079</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2022-06-01T18:33:17Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Array And Do while to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Array-And-Do-while-to-SQL/m-p/816088#M322080</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I'd like to understand array part and do while loop&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What don't you understand about them?&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2022 18:59:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Array-And-Do-while-to-SQL/m-p/816088#M322080</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-01T18:59:32Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Array And Do while to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Array-And-Do-while-to-SQL/m-p/816091#M322082</link>
      <description>&lt;P&gt;Maxim 1: Read the Documentation.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p08do6szetrxe2n136ush727sbuo.htm" target="_blank" rel="noopener"&gt;ARRAY&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p1awxgleif5wlen1pja0nrn6yi6i.htm" target="_blank" rel="noopener"&gt;DO WHILE&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code suggests that there is data in structure (dates in variable names), which is always a&amp;nbsp;&lt;STRONG&gt;VERY BAD IDEA&lt;/STRONG&gt; and the main cause why array processing is needed. And this array processing is the #1 reason why you can't do this in SQL&lt;/P&gt;
&lt;P&gt;This&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;IF FIRST.MATERIAL THEN 
  DO;
    ARRAY FCT(*) &amp;amp;FCST_D2.;
  END;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is total bogus and misleading to the unwary SAS novice, as ARRAY is a declarative statement which cannot be executed conditionally.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get this mess straight, we need to see proper and useful (read: data step with datalines) examples of the datasets.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2022 19:12:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Array-And-Do-while-to-SQL/m-p/816091#M322082</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-06-01T19:12:06Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Array And Do while to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Array-And-Do-while-to-SQL/m-p/816118#M322091</link>
      <description>Can you provide an example of the input data? It's not always straightforward to convert when the code is dynamic. &lt;BR /&gt;&lt;BR /&gt;Just a guess, it looks like an expansion of data, possibly expanding a status of something over time. &lt;BR /&gt;Definitely not something I'd try with SQL. &lt;BR /&gt;</description>
      <pubDate>Wed, 01 Jun 2022 21:00:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Array-And-Do-while-to-SQL/m-p/816118#M322091</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-06-01T21:00:40Z</dc:date>
    </item>
  </channel>
</rss>

