<?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 assign different value to a new variable with do loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-value-to-a-new-variable-with-do-loop/m-p/525639#M143037</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;	
	input provision1 provision2 provision3 provision4 flow $20.;
datalines;
5 5 8 7 increase
0 0 4 4 inflow
0 2 3 3 inflow
8 8 8 0 outflow
;
run;

data want;
set have;
array t(*) provision4-provision1;
if flow='inflow' then do;
k=whichn(0,of t(*)); 
if k&amp;gt;1 then impact=t(k-1); 
end;
drop k;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 09 Jan 2019 04:16:49 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-01-09T04:16:49Z</dc:date>
    <item>
      <title>How to assign different value to a new variable with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-value-to-a-new-variable-with-do-loop/m-p/525616#M143024</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I hava a dataset like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;	
	input provision1 provision2 provision3 provision4 flow $20.;
datalines;
5 5 8 7 increase
0 0 4 4 inflow
0 2 3 3 inflow
8 8 8 0 outflow
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;I'm trying to create a new variable (impact) and, if flow = "Inflow", I would like assign it the first provision greater then zero&lt;/STRONG&gt;, in my example provision03 for the 2nd observation and provision2 for the third observation. In the other case provision will be missing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying with this code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
	set have;
	array prov {*}  provision1 provision2 provision3 provision4;
	if flow = "inflow" then do;
		impact = 0;
		do i = 1 to 4 until(prov{i} eq 0);
			impact = prov{i+1};
		end;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think there is some problem because the value for impact in the new dataset are 0 (2nd obs) and 2 (3rd obs) and not 4 and 2 as I would like.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I hope I have explained my need well, could you help me please...? Thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Daniele&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jan 2019 23:48:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-value-to-a-new-variable-with-do-loop/m-p/525616#M143024</guid>
      <dc:creator>Ccasagran737</dc:creator>
      <dc:date>2019-01-08T23:48:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign different value to a new variable with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-value-to-a-new-variable-with-do-loop/m-p/525620#M143026</link>
      <description>&lt;P&gt;I believe you need to change your until condition&lt;/P&gt;
&lt;P&gt;from:&lt;/P&gt;
&lt;P&gt;do i = 1 to 4 until(prov{i}&amp;nbsp;&lt;STRONG&gt;eq&lt;/STRONG&gt; 0);&lt;/P&gt;
&lt;P&gt;to:&lt;/P&gt;
&lt;P&gt;do i = 1 to 4 until(prov{i} &lt;STRONG&gt;ne&lt;/STRONG&gt; 0);&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jan 2019 00:07:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-value-to-a-new-variable-with-do-loop/m-p/525620#M143026</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-01-09T00:07:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign different value to a new variable with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-value-to-a-new-variable-with-do-loop/m-p/525624#M143027</link>
      <description>&lt;P&gt;The following will give the desired result.&lt;/P&gt;
&lt;P&gt;data work.test (drop=i);&lt;BR /&gt; set work.have;&lt;BR /&gt; array prov {*} provision1 provision2 provision3 provision4;&lt;BR /&gt; if flow = "inflow" then do;&lt;BR /&gt; impact = 0;&lt;BR /&gt; do i = 1 to 3 ; &lt;BR /&gt; test=0;&lt;BR /&gt; if prov{i+1}&amp;gt;test then test=prov{i+1};&lt;BR /&gt; if test &amp;gt;0 then leave;&lt;BR /&gt;end;&lt;BR /&gt;output;&lt;BR /&gt; end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jan 2019 00:25:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-value-to-a-new-variable-with-do-loop/m-p/525624#M143027</guid>
      <dc:creator>thesasuser</dc:creator>
      <dc:date>2019-01-09T00:25:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign different value to a new variable with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-value-to-a-new-variable-with-do-loop/m-p/525628#M143028</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
	set have;
	array prov {*}  provision1 provision2 provision3 provision4;
  
	if flow = "inflow" then do;
		impact = 0;
		do i = 1 to dim(prov) ;
			if prov[i] &amp;gt; 0 then do ;
				impact =prov[i];
				leave;
			end;
		end;
	end;
	drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Jan 2019 01:48:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-value-to-a-new-variable-with-do-loop/m-p/525628#M143028</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2019-01-09T01:48:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign different value to a new variable with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-value-to-a-new-variable-with-do-loop/m-p/525639#M143037</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;	
	input provision1 provision2 provision3 provision4 flow $20.;
datalines;
5 5 8 7 increase
0 0 4 4 inflow
0 2 3 3 inflow
8 8 8 0 outflow
;
run;

data want;
set have;
array t(*) provision4-provision1;
if flow='inflow' then do;
k=whichn(0,of t(*)); 
if k&amp;gt;1 then impact=t(k-1); 
end;
drop k;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Jan 2019 04:16:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-value-to-a-new-variable-with-do-loop/m-p/525639#M143037</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-09T04:16:49Z</dc:date>
    </item>
  </channel>
</rss>

