<?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 Seek help on Create new var with Do Loop in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Seek-help-on-Create-new-var-with-Do-Loop/m-p/264794#M7295</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;I want to create new variables (newna1-newna5) from na1 -na5, if there is missing value of na then &lt;BR /&gt;newna will be equal to the previous nonmissing value of na.&lt;BR /&gt;But I have problems running the program below, error with array length.&lt;BR /&gt;Please help me to figure it out.&lt;BR /&gt;Thank you very much&lt;BR /&gt;&lt;BR /&gt;data try;
	input id na1 na2 na3 na4 na5;
	datalines;
1 2 3 . . 4 
2 3 5 4 1 .
3 6 . 7 5 4
4 5 3 . 4 .
5 4 . . . 6
;
run;

data try1;
	set try;
	array na(*) na1-na5;
	array newna(*) newna1-newna5;

	do i=1 to 5;
	newna(i)=na(i);
                do j=1 to 4;
		if na(i)=. then newna(i)=na(i-j);
		end;
		
	end;
run;

		output;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 19 Apr 2016 14:58:21 GMT</pubDate>
    <dc:creator>Minhtrang</dc:creator>
    <dc:date>2016-04-19T14:58:21Z</dc:date>
    <item>
      <title>Seek help on Create new var with Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Seek-help-on-Create-new-var-with-Do-Loop/m-p/264794#M7295</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;I want to create new variables (newna1-newna5) from na1 -na5, if there is missing value of na then &lt;BR /&gt;newna will be equal to the previous nonmissing value of na.&lt;BR /&gt;But I have problems running the program below, error with array length.&lt;BR /&gt;Please help me to figure it out.&lt;BR /&gt;Thank you very much&lt;BR /&gt;&lt;BR /&gt;data try;
	input id na1 na2 na3 na4 na5;
	datalines;
1 2 3 . . 4 
2 3 5 4 1 .
3 6 . 7 5 4
4 5 3 . 4 .
5 4 . . . 6
;
run;

data try1;
	set try;
	array na(*) na1-na5;
	array newna(*) newna1-newna5;

	do i=1 to 5;
	newna(i)=na(i);
                do j=1 to 4;
		if na(i)=. then newna(i)=na(i-j);
		end;
		
	end;
run;

		output;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Apr 2016 14:58:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Seek-help-on-Create-new-var-with-Do-Loop/m-p/264794#M7295</guid>
      <dc:creator>Minhtrang</dc:creator>
      <dc:date>2016-04-19T14:58:21Z</dc:date>
    </item>
    <item>
      <title>Re: Seek help on Create new var with Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Seek-help-on-Create-new-var-with-Do-Loop/m-p/264805#M7296</link>
      <description>&lt;P&gt;You could simplify the process and get the correct result most of the time:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; try1&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	&lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; try&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	&lt;SPAN class="token statement"&gt;array&lt;/SPAN&gt; na&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; na1&lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt;na5&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	&lt;SPAN class="token statement"&gt;array&lt;/SPAN&gt; newna&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; newna1&lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt;newna5&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

	do i&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; to &lt;SPAN class="token number"&gt;5&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	   if na(i) &amp;gt; . then newna&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;i&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;na&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;i&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	   else newna&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;i&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=new&lt;/SPAN&gt;na&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;i&lt;SPAN class="token operator"&gt;-1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	end&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I say "most of the time" I'm looking at the possibility that na1 might be missing.&amp;nbsp; What should happen in that case?&amp;nbsp; The program will generate an error as it stands now.&amp;nbsp; So if it's possible that na1 might be missing, you would need to specify what the result should be so the program can be modified. &lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2016 15:19:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Seek-help-on-Create-new-var-with-Do-Loop/m-p/264805#M7296</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-04-19T15:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: Seek help on Create new var with Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Seek-help-on-Create-new-var-with-Do-Loop/m-p/264937#M7307</link>
      <description>&lt;P&gt;Dear Astouding,&lt;/P&gt;
&lt;P&gt;Thanks a lot for your help.&lt;/P&gt;
&lt;P&gt;It's so simple!&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;Trang&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2016 22:40:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Seek-help-on-Create-new-var-with-Do-Loop/m-p/264937#M7307</guid>
      <dc:creator>Minhtrang</dc:creator>
      <dc:date>2016-04-19T22:40:05Z</dc:date>
    </item>
  </channel>
</rss>

