<?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: Vararray in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Vararray-in-PROC-DS2/m-p/416371#M102225</link>
    <description>&lt;DIV class="tw-swapa"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="_Ejb"&gt;&lt;DIV&gt;&lt;DIV class="tw-nfl tw-ta-container"&gt;&lt;SPAN&gt;It is necessary to create an array for storing the information that I download from the database.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="tw-nfl tw-ta-container"&gt;&lt;PRE&gt;&lt;FONT size="1"&gt;&lt;FONT face="Courier New"&gt;proc ds2;

package qqq/overwrite=yes;

 

vararray double mothpayment[n]; &amp;lt;- n Number of Payments, this number is not known in advance. This means that we do not know in advance what length the array will be.


 

dcl package SQLStmt stmtCredits('SELECT count(*) FROM WORK.monthly_payment t');

 

method execute()After we execute the query, we get a number that means the size of the array mothpayment

rc= stmtCredits.execute();

if (rc = 0) then do; 

rc= stmtCredits.bindresults([count]);

rc= stmtCredits.fetch();

rc = stmtCredits.fetch();

end;

end; &lt;/FONT&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1"&gt;so the question is how to set the array correctly or how to write the code correctly so that in the future the size of the array is equal to the number of rows received from the database&lt;/FONT&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Mon, 27 Nov 2017 13:15:51 GMT</pubDate>
    <dc:creator>Liliya95</dc:creator>
    <dc:date>2017-11-27T13:15:51Z</dc:date>
    <item>
      <title>Vararray in PROC DS2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Vararray-in-PROC-DS2/m-p/416318#M102223</link>
      <description>&lt;P&gt;How to work with arrays in ds2? There is an array in the proc step. Need to create it indefinite long, the length of the array will consist of the amount of data loaded from the database&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 13:55:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Vararray-in-PROC-DS2/m-p/416318#M102223</guid>
      <dc:creator>Liliya95</dc:creator>
      <dc:date>2017-11-27T13:55:45Z</dc:date>
    </item>
    <item>
      <title>Re: Vararray</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Vararray-in-PROC-DS2/m-p/416321#M102224</link>
      <description>&lt;P&gt;I am sorry, please review the how to post a question text which you find next to the post information.&amp;nbsp; You have to provide some information for us to work with.&amp;nbsp; You mention ds2, why/how are you using this, providing code is useful - use the code window (its the {i} above post area).&amp;nbsp; You talk about varrays, which I assume you picked up from here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sgf/2016/04/22/solutions-for-many-of-the-missing-data-step-features-within-ds2/" target="_blank"&gt;https://blogs.sas.com/content/sgf/2016/04/22/solutions-for-many-of-the-missing-data-step-features-within-ds2/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;These tend to need pre-known item counts, but there are ways around it.&amp;nbsp; But then your statement "&lt;SPAN&gt;Need to create it indefinite long, the length of the array will consist of the amount of data loaded from the database&lt;/SPAN&gt;&lt;STRONG&gt;"&amp;nbsp;&lt;/STRONG&gt;seems to imply that you do not know what arrays are for.&amp;nbsp; They are temporary references to a group of variables - nothing to do with observations, so you know the structure of your data, that is all that is necessary to be able to create an array on the structure.&amp;nbsp; Again though, you haven't provided any information that would help us understand your problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 11:18:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Vararray-in-PROC-DS2/m-p/416321#M102224</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-27T11:18:30Z</dc:date>
    </item>
    <item>
      <title>Re: Vararray</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Vararray-in-PROC-DS2/m-p/416371#M102225</link>
      <description>&lt;DIV class="tw-swapa"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="_Ejb"&gt;&lt;DIV&gt;&lt;DIV class="tw-nfl tw-ta-container"&gt;&lt;SPAN&gt;It is necessary to create an array for storing the information that I download from the database.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="tw-nfl tw-ta-container"&gt;&lt;PRE&gt;&lt;FONT size="1"&gt;&lt;FONT face="Courier New"&gt;proc ds2;

package qqq/overwrite=yes;

 

vararray double mothpayment[n]; &amp;lt;- n Number of Payments, this number is not known in advance. This means that we do not know in advance what length the array will be.


 

dcl package SQLStmt stmtCredits('SELECT count(*) FROM WORK.monthly_payment t');

 

method execute()After we execute the query, we get a number that means the size of the array mothpayment

rc= stmtCredits.execute();

if (rc = 0) then do; 

rc= stmtCredits.bindresults([count]);

rc= stmtCredits.fetch();

rc = stmtCredits.fetch();

end;

end; &lt;/FONT&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1"&gt;so the question is how to set the array correctly or how to write the code correctly so that in the future the size of the array is equal to the number of rows received from the database&lt;/FONT&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 27 Nov 2017 13:15:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Vararray-in-PROC-DS2/m-p/416371#M102225</guid>
      <dc:creator>Liliya95</dc:creator>
      <dc:date>2017-11-27T13:15:51Z</dc:date>
    </item>
    <item>
      <title>Re: Vararray</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Vararray-in-PROC-DS2/m-p/416377#M102226</link>
      <description>&lt;P&gt;Yes, and here is the nub of my point.&amp;nbsp; Arrays deal with variables, not observations.&amp;nbsp; So if your data is structured like this:&lt;/P&gt;
&lt;P&gt;monthpayment1 monthpayment2 ... monthpaymentX&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;then arrays would be there to deal with with this and you can get this from the data structure.&amp;nbsp; If however your database is designed by anyone with any sense, your data will be normalised, something like:&lt;/P&gt;
&lt;P&gt;month&amp;nbsp; &amp;nbsp;payment&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;...&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;..&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Arrays are not the way to handle this type of data, that is for aggregate functions in SQL, or datastep in SAS.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So again, I ask what does your data look like, post an example - doesn't have to be real - in the form of a datastep (you can follow:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712).&amp;nbsp;" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712).&amp;nbsp;&lt;/A&gt; This will show your data.&amp;nbsp; Next question is, why are you using proc ds2?&amp;nbsp; If you have the data downloaded from a database, you can use simple datastep language to process it.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 13:26:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Vararray-in-PROC-DS2/m-p/416377#M102226</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-27T13:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: Vararray</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Vararray-in-PROC-DS2/m-p/416387#M102227</link>
      <description>&lt;PRE&gt;my table with monthly payments&lt;BR /&gt;&lt;BR /&gt;data mothly_payment;/*Временная таблица платежей*/
   attrib P length = 8;
 
   infile datalines dsd;
   input
     P
   ;
datalines4;
9000
6002,
172,
1700,
1500,
800,
2800,
305,
1900,
;;;;
run;&lt;/PRE&gt;&lt;PRE&gt;my code&lt;BR /&gt;&lt;BR /&gt;proc ds2;
package qqq/overwrite=yes; 
vararray double mothpayment[n];
dcl double Ost;
dcl int s rc rc1 i j h k n count;

dcl package SQLStmt stmtCount('SELECT count(*) FROM WORK.monthly_payment t');

dcl package SQLStmt stmtCredits('SELECT t.m_p FROM WORK.monthly_payment t order by t.m_p desc');

method execute()

Ost =11903;
minsum=0;

rc= stmtCount.execute();
if (rc = 0) then do; 
rc= stmtCount.bindresults([count]);
rc= stmtCount.fetch();
rc = stmtCount.fetch();
end;


	rc=	stmtCredits.execute(); 

				if (rc = 0) then do;
							rc=	stmtCredits.bindresults([MonthlyPaymentCC]); 
							rc=	stmtCredits.fetch();	

									i=1;put count= ; 								
										do while (i&amp;lt;=count);put MonthlyPaymentCC= ;
											mothpayment[i] = MonthlyPaymentCC;
											minsum=minsum+MonthlyPaymentCC;											
											rc = stmtCredits.fetch();							
											i=i+1;
										end;
										put mothpayment[*]= ;
										put minsum= ;

							
				end; 
 		
				n=1;
				do i=1 to count;
					if(mothpayment[i]&amp;gt;=Ost) then do;
 						minsum=mothpayment[i]; n=i; inddd=i;				
					end;
				end;
			put minsum= ;		


end; &lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Nov 2017 13:52:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Vararray-in-PROC-DS2/m-p/416387#M102227</guid>
      <dc:creator>Liliya95</dc:creator>
      <dc:date>2017-11-27T13:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: Vararray</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Vararray-in-PROC-DS2/m-p/416389#M102228</link>
      <description>&lt;P&gt;&lt;SPAN&gt;please help me figure it out. I'm just starting to learn ds2 and do not know many things&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 13:53:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Vararray-in-PROC-DS2/m-p/416389#M102228</guid>
      <dc:creator>Liliya95</dc:creator>
      <dc:date>2017-11-27T13:53:52Z</dc:date>
    </item>
    <item>
      <title>Re: Vararray</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Vararray-in-PROC-DS2/m-p/416394#M102229</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Sorry, not sure how I can say this any other way.&amp;nbsp; An array is an array of variables not observations.&amp;nbsp; You have only one variable, therefore your "array" would be one data item each row - i.e. there is no array.&amp;nbsp; Perhaps start by learning how to do your task in Base SAS using datasteps before jumping into ds2.&amp;nbsp; To note, varray just checks if the variable is part of an array.&amp;nbsp; As for using ds2, not found a use for it as yet, Base SAS does everything.&amp;nbsp; Download your data to a SAS dataset and then process it using Base SAS.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 13:59:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Vararray-in-PROC-DS2/m-p/416394#M102229</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-27T13:59:54Z</dc:date>
    </item>
    <item>
      <title>Re: Vararray</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Vararray-in-PROC-DS2/m-p/416396#M102231</link>
      <description>&lt;P&gt;&lt;SPAN&gt;can you write an example of using an array on sas base please?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 14:10:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Vararray-in-PROC-DS2/m-p/416396#M102231</guid>
      <dc:creator>Liliya95</dc:creator>
      <dc:date>2017-11-27T14:10:13Z</dc:date>
    </item>
    <item>
      <title>Re: Vararray</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Vararray-in-PROC-DS2/m-p/416399#M102232</link>
      <description>&lt;P&gt;Here is a good paper on the subject:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.sas.com/content/dam/SAS/support/en/technical-papers/arrays1780.pdf" target="_blank"&gt;https://www.sas.com/content/dam/SAS/support/en/technical-papers/arrays1780.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 14:15:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Vararray-in-PROC-DS2/m-p/416399#M102232</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-27T14:15:00Z</dc:date>
    </item>
    <item>
      <title>Re: Vararray</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Vararray-in-PROC-DS2/m-p/416401#M102234</link>
      <description>&lt;P&gt;Thanks so much!&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 14:17:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Vararray-in-PROC-DS2/m-p/416401#M102234</guid>
      <dc:creator>Liliya95</dc:creator>
      <dc:date>2017-11-27T14:17:22Z</dc:date>
    </item>
  </channel>
</rss>

