<?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 put dim(ArrayName) into macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-put-dim-ArrayName-into-macro-variable/m-p/537114#M147659</link>
    <description>&lt;P&gt;Use SYMGET then to get the macro variable or separate it into two steps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159193"&gt;@sburnos&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for the reply.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately, this does not work as I need to count the dimension of the array.&lt;/P&gt;
&lt;P&gt;If I use the&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrostatement"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;countw&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the result of the length_var =1, but I need it to be 6.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Feb 2019 15:44:07 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-02-20T15:44:07Z</dc:date>
    <item>
      <title>how to put dim(ArrayName) into macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-put-dim-ArrayName-into-macro-variable/m-p/537102#M147650</link>
      <description>&lt;P&gt;Dear All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;could you please suggest a solution for the following issue, I cannot save the dim(ArrayName) into a macro variable in order to use it later:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data test;&lt;BR /&gt;var_test___1=0;&lt;BR /&gt;var_test___2=1;&lt;BR /&gt;var_test___3=1;&lt;BR /&gt;var_test___4=1;&lt;BR /&gt;var_test___5=0;&lt;BR /&gt;var_test___6=0;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro instrument_inarow(var= );&lt;BR /&gt;%local j var_length;&lt;BR /&gt;data output_data;&lt;BR /&gt;set test(keep=&amp;amp;var.: );&lt;BR /&gt;array list_asc(*) &amp;amp;var.:;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;call symputx('var_length',dim(list_asc),'G'); * HERE is the issue, I need to assign to var_length = dim(list_asc)*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;array list_desc(*)&lt;BR /&gt;%do j=&amp;amp;var_length. %to 1 %by -1;&lt;BR /&gt;&amp;amp;var.___&amp;amp;j.&lt;BR /&gt;%end;&lt;BR /&gt;%str(; );&lt;/P&gt;&lt;P&gt;if 1 then flg=1; /*here comes some conditions*/&lt;BR /&gt;else flg=0;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%instrument_inarow(var=var_test);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What would be a solution?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks in advance!&lt;/P&gt;</description>
      <pubDate>Wed, 20 Feb 2019 15:35:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-put-dim-ArrayName-into-macro-variable/m-p/537102#M147650</guid>
      <dc:creator>sburnos</dc:creator>
      <dc:date>2019-02-20T15:35:06Z</dc:date>
    </item>
    <item>
      <title>Re: how to put dim(ArrayName) into macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-put-dim-ArrayName-into-macro-variable/m-p/537105#M147653</link>
      <description>&lt;P&gt;You cannot use a macro variable in the same step where it is created. To count the number of items in &amp;amp;var, use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%sysfunc(countw(&amp;amp;var.))&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Feb 2019 15:30:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-put-dim-ArrayName-into-macro-variable/m-p/537105#M147653</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-02-20T15:30:10Z</dc:date>
    </item>
    <item>
      <title>Re: how to put dim(ArrayName) into macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-put-dim-ArrayName-into-macro-variable/m-p/537108#M147656</link>
      <description>&lt;P&gt;Thanks for the reply.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, this does not work as I need to count the dimension of the array.&lt;/P&gt;&lt;P&gt;If I use the&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrostatement"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;countw&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;the result of the length_var =1, but I need it to be 6.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Feb 2019 15:34:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-put-dim-ArrayName-into-macro-variable/m-p/537108#M147656</guid>
      <dc:creator>sburnos</dc:creator>
      <dc:date>2019-02-20T15:34:03Z</dc:date>
    </item>
    <item>
      <title>Re: how to put dim(ArrayName) into macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-put-dim-ArrayName-into-macro-variable/m-p/537114#M147659</link>
      <description>&lt;P&gt;Use SYMGET then to get the macro variable or separate it into two steps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159193"&gt;@sburnos&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for the reply.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately, this does not work as I need to count the dimension of the array.&lt;/P&gt;
&lt;P&gt;If I use the&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrostatement"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;countw&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the result of the length_var =1, but I need it to be 6.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Feb 2019 15:44:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-put-dim-ArrayName-into-macro-variable/m-p/537114#M147659</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-20T15:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: how to put dim(ArrayName) into macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-put-dim-ArrayName-into-macro-variable/m-p/537119#M147662</link>
      <description>It's mildly awkward but you can break up the data step into 2 steps.  After call symputx, insert into the program:&lt;BR /&gt;&lt;BR /&gt;stop;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;At that point you have the macro variable and can repeat the beginning of the data step:&lt;BR /&gt;&lt;BR /&gt;Data&lt;BR /&gt;Set&lt;BR /&gt;Array&lt;BR /&gt;Array&lt;BR /&gt;%do</description>
      <pubDate>Wed, 20 Feb 2019 15:56:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-put-dim-ArrayName-into-macro-variable/m-p/537119#M147662</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-02-20T15:56:53Z</dc:date>
    </item>
    <item>
      <title>Re: how to put dim(ArrayName) into macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-put-dim-ArrayName-into-macro-variable/m-p/537123#M147664</link>
      <description>Maybe I am short-sighted, but why do you need the dimension in a macro-variable? Why not just query sashelp.vcolumn and create a macro variable with the names of the variables?</description>
      <pubDate>Wed, 20 Feb 2019 16:24:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-put-dim-ArrayName-into-macro-variable/m-p/537123#M147664</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-02-20T16:24:06Z</dc:date>
    </item>
    <item>
      <title>Re: how to put dim(ArrayName) into macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-put-dim-ArrayName-into-macro-variable/m-p/537125#M147665</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159193"&gt;@sburnos&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wonder why you are doing this. You are building a new array with the same variables in reverse order. It does not affect the order of variables in your output, so I guess it serves some purpose in your real code, where you have a dummy condition in your example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have the dimension available in the data step, so it might be possible to do the same thing on the original array by using 2 index variables, one going from 1 to dim, and another from dim to 1. By the way, do you have more than one record in real data? - in that case your array will always contain the full set of variables, whether missing in the actual record or not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Feb 2019 16:26:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-put-dim-ArrayName-into-macro-variable/m-p/537125#M147665</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-02-20T16:26:39Z</dc:date>
    </item>
    <item>
      <title>Re: how to put dim(ArrayName) into macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-put-dim-ArrayName-into-macro-variable/m-p/537334#M147773</link>
      <description>&lt;P&gt;You can not use a macro variable created in same datastep.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Re-Written Code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
var_test___1=0;
var_test___2=1;
var_test___3=1;
var_test___4=1;
var_test___5=0;
var_test___6=0;
run;
 
option mprint mlogic symbolgen source source2;
%macro instrument_inarow(var= );
	%local j var_length;
	
	data _null_;
	set test(keep=&amp;amp;var.: );
	array list_asc(*) &amp;amp;var.:;
	call symput('var_length',dim(list_asc)); 
	stop;
	run;

	data output_data;
	set test(keep=&amp;amp;var.: );
	array list_desc(*)
	%do j=&amp;amp;var_length. %to 1 %by -1;
		&amp;amp;var.___&amp;amp;j.
	%end;
	%str(; );
	if 1 then flg=1; 
	else flg=0;
	run;
%mend instrument_inarow;

%instrument_inarow(var=var_test);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Please let us know if it worked.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Feb 2019 07:57:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-put-dim-ArrayName-into-macro-variable/m-p/537334#M147773</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2019-02-21T07:57:09Z</dc:date>
    </item>
  </channel>
</rss>

