<?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 Array help with inventory tracking table in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Array-help-with-inventory-tracking-table/m-p/484810#M71852</link>
    <description>&lt;P&gt;I'm trying to create a table that will show the demand for an item until it hits below the current inventory in which case the columns would show the total negative demand.&amp;nbsp; The inputs I am receiving are never in the same format that is why I have to use the proc contents function.&amp;nbsp; Please see my table example below (this is a very simplified version)&amp;nbsp; and the code I've got so far.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 580px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/22304i486D88E3398DE9D1/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA HAVE;
infile datalines delimiter=',';
INPUT 
ITEM $ INVENTORY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY;
DATALINES;
1A,57,8,.,10,7,38,.
1B,.,.,45,11,.,76,96
1C,49,.,.,44,96,53,49
1D,80,.,85,14,55,.,2
1E,29,23,34,61,.,12,.

;
RUN;

PROC CONTENTS
DATA = HAVE
OUT = CONT;
RUN;

PROC SQL;
	CREATE TABLE CONT1 AS
	SELECT
	NAME AS COL,
	VARNUM AS COL_NUM
FROM CONT 
WHERE VARNUM &amp;gt; 1
ORDER BY VARNUM;
QUIT;


 proc sql noprint;
 select  COL
 into :varnames separated by ' '
 from CONT1
order by COL_NUM;
 quit;

%PUT NOTE: &amp;amp;varnames;

data want;
    set HAVE;
    array x &amp;amp;varnames;
    do i= 2 to dim(x);
	if x(i)=. then x(i) = x(i-1);
 	else x(i)= x(i-1) - x(i);
    end;
    drop i;
run;


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Aug 2018 16:14:09 GMT</pubDate>
    <dc:creator>dane77221</dc:creator>
    <dc:date>2018-08-07T16:14:09Z</dc:date>
    <item>
      <title>Array help with inventory tracking table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Array-help-with-inventory-tracking-table/m-p/484810#M71852</link>
      <description>&lt;P&gt;I'm trying to create a table that will show the demand for an item until it hits below the current inventory in which case the columns would show the total negative demand.&amp;nbsp; The inputs I am receiving are never in the same format that is why I have to use the proc contents function.&amp;nbsp; Please see my table example below (this is a very simplified version)&amp;nbsp; and the code I've got so far.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 580px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/22304i486D88E3398DE9D1/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA HAVE;
infile datalines delimiter=',';
INPUT 
ITEM $ INVENTORY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY;
DATALINES;
1A,57,8,.,10,7,38,.
1B,.,.,45,11,.,76,96
1C,49,.,.,44,96,53,49
1D,80,.,85,14,55,.,2
1E,29,23,34,61,.,12,.

;
RUN;

PROC CONTENTS
DATA = HAVE
OUT = CONT;
RUN;

PROC SQL;
	CREATE TABLE CONT1 AS
	SELECT
	NAME AS COL,
	VARNUM AS COL_NUM
FROM CONT 
WHERE VARNUM &amp;gt; 1
ORDER BY VARNUM;
QUIT;


 proc sql noprint;
 select  COL
 into :varnames separated by ' '
 from CONT1
order by COL_NUM;
 quit;

%PUT NOTE: &amp;amp;varnames;

data want;
    set HAVE;
    array x &amp;amp;varnames;
    do i= 2 to dim(x);
	if x(i)=. then x(i) = x(i-1);
 	else x(i)= x(i-1) - x(i);
    end;
    drop i;
run;


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 16:14:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Array-help-with-inventory-tracking-table/m-p/484810#M71852</guid>
      <dc:creator>dane77221</dc:creator>
      <dc:date>2018-08-07T16:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: Array help with inventory tracking table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Array-help-with-inventory-tracking-table/m-p/484820#M71854</link>
      <description>&lt;P&gt;You need to have a variable named&amp;nbsp;cumulative_inventory, which for Item 1A starts at 57.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you subtract the demand from cumulative Inventory.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If cumulative inventory is still positive, then you leave the value of the demand in the output table as a positive number; if cumulative Inventory becomes negative, then the value in the output table becomes the negative number&amp;nbsp;of cumulative inventory. (This seems like a very strange and somewhat misleading way to table this information, but that seems to be what you have asked for).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;cumulative_inventory=inventory;

do i=1 to dim(x);
    cumulative_inventory = cumulative_inventory - x(i);
    if cumulative_inventory&amp;lt;0 then x(i) = cumulative_inventory;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 16:49:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Array-help-with-inventory-tracking-table/m-p/484820#M71854</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-08-07T16:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: Array help with inventory tracking table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Array-help-with-inventory-tracking-table/m-p/484827#M71855</link>
      <description>&lt;P&gt;Thank you for looking into this!&lt;/P&gt;&lt;P&gt;Below is the output I got by trying to implement what you are suggesting.&lt;/P&gt;&lt;P&gt;Maybe i'm doing it wrong but also I need to show a blank cell when there is no demand&lt;/P&gt;&lt;P&gt;any Ideas on how I could do that?&lt;/P&gt;&lt;P&gt;Please Advise&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/22307i7BAE0B741BAB6F58/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA HAVE;
infile datalines delimiter=',';
INPUT 
ITEM $ INVENTORY CUM_INV MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY;
DATALINES;
1A,57,57,8,.,10,7,38,.
1B,.,.,.,45,11,.,76,96
1C,49,49,.,.,44,96,53,49
1D,80,80,.,85,14,55,.,2
1E,29,29,23,34,61,.,12,.

;
RUN;

PROC CONTENTS
DATA = HAVE
OUT = CONT;
RUN;

PROC SQL;
	CREATE TABLE CONT1 AS
	SELECT
	NAME AS COL,
	VARNUM AS COL_NUM
FROM CONT 
WHERE VARNUM &amp;gt; 2
ORDER BY VARNUM;
QUIT;


 proc sql noprint;
 select  COL
 into :varnames separated by ' '
 from CONT1
order by COL_NUM;
 quit;

%PUT NOTE: &amp;amp;varnames;

data want;
    set HAVE;
    array x &amp;amp;varnames;
   do i= 2 to dim(x);
	if x(i)=. then x(i) = x(i-1);
 	else x(i)= x(i-1) - x(i);
    end;
    drop i;
run;
DATA WANT2;
	SET want;
array x &amp;amp;varnames;
do i=1 to dim(x);
    CUM_INV = CUM_INV - x(i);
    if CUM_INV &amp;lt; 0 then x(i) = CUM_INV;
end;
DROP i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Aug 2018 17:02:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Array-help-with-inventory-tracking-table/m-p/484827#M71855</guid>
      <dc:creator>dane77221</dc:creator>
      <dc:date>2018-08-07T17:02:31Z</dc:date>
    </item>
    <item>
      <title>Re: Array help with inventory tracking table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Array-help-with-inventory-tracking-table/m-p/484839#M71856</link>
      <description>&lt;P&gt;The first line of code I provided seems to be missing from your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also you shouldn't have DATA WANT; followed by DATA WANT2; Just do the loop that is now in DATA WANT2; plus the one line you missed.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 17:53:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Array-help-with-inventory-tracking-table/m-p/484839#M71856</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-08-07T17:53:09Z</dc:date>
    </item>
    <item>
      <title>Re: Array help with inventory tracking table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Array-help-with-inventory-tracking-table/m-p/484842#M71857</link>
      <description>&lt;P&gt;Minor correction to my ocde&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;cumulative_inventory=inventory;

do i=1 to dim(x);
    cumulative_inventory = sum(cumulative_inventory, -x(i));
    if cumulative_inventory&amp;lt;0 then x(i) = cumulative_inventory;
end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Aug 2018 17:56:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Array-help-with-inventory-tracking-table/m-p/484842#M71857</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-08-07T17:56:03Z</dc:date>
    </item>
  </channel>
</rss>

