<?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: My array is not working, could someone point out how i can concatenate these values? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/My-array-is-not-working-could-someone-point-out-how-i-can/m-p/868033#M342846</link>
    <description>The Length Statement is executed once during the compilation phase, which in turn, would declare the 'want' variable in the PDV, and assign it a blank.&lt;BR /&gt;&lt;BR /&gt;As you loop through the data set records via the SET statement, you want to make sure to explicitly reset the 'want' variable back to blank, before using in the catx function within the loop.&lt;BR /&gt;&lt;BR /&gt;Hope this helps</description>
    <pubDate>Tue, 04 Apr 2023 17:11:07 GMT</pubDate>
    <dc:creator>AhmedAl_Attar</dc:creator>
    <dc:date>2023-04-04T17:11:07Z</dc:date>
    <item>
      <title>My array is not working, could someone point out how i can concatenate these values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-array-is-not-working-could-someone-point-out-how-i-can/m-p/868022#M342835</link>
      <description>&lt;P&gt;Hi, the purpose of this exercise is to concatenate these values. I'm still new to arrays, and was wondering if i can receive some help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
infile datalines dsd dlm=",";
	input subject $ apple $ orange $ banana $ grape $ cherry $ jackfruit $;
datalines;
001, Y, , Y, , , Y
002, , , , Y, , Y
003, , , , , , 
;
run;


data want; set have; /* does not work*/
array tmp{*} apple--jackfruit;
	want=catx(", ", of tmp:);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The desired output i need is:&lt;/P&gt;
&lt;P&gt;subject&lt;/P&gt;
&lt;P&gt;001&amp;nbsp;&amp;nbsp;&amp;nbsp; apple, banana, jackfruit&lt;/P&gt;
&lt;P&gt;002&amp;nbsp;&amp;nbsp;&amp;nbsp; grape, jackfruit&lt;/P&gt;
&lt;P&gt;003&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 16:31:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-array-is-not-working-could-someone-point-out-how-i-can/m-p/868022#M342835</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-04-04T16:31:57Z</dc:date>
    </item>
    <item>
      <title>Re: My array is not working, could someone point out how i can concatenate these values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-array-is-not-working-could-someone-point-out-how-i-can/m-p/868023#M342836</link>
      <description>&lt;P&gt;You appear to want the NAME of the variable and not the VALUE of the variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  length want $200;
  array tmp apple--jackfruit;
  do index=1 to dim(tmp);
    if tmp[index]='Y' then want=catx(', ',want,vname(tmp[index]));
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Apr 2023 16:44:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-array-is-not-working-could-someone-point-out-how-i-can/m-p/868023#M342836</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-04T16:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: My array is not working, could someone point out how i can concatenate these values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-array-is-not-working-could-someone-point-out-how-i-can/m-p/868024#M342837</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/252358"&gt;@Hello_there&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even if your CATX function were to work, it would concatenate the values of 'Y' or missing values; it would not concatenate the name of the fruits because those are variable names, not variable values that CATX would work on.&amp;nbsp;So you can't do it that way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to loop through the different values in the array TMP, test to see if the value is 'Y', and then capture the name of the fruit from the variable name of the column where the 'Y' is located, and then concatenate. All of these steps are missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want; 
    set have; /* does not work*/
    array tmp{*} apple--jackfruit;
    length want_result $ 200;
    want_result=' ';
    do i=1 to dim(tmp);
        if tmp(i)='Y' then 
    	want_result=catx(", ",want_result,vname(tmp(i)));
    end;
    drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Apr 2023 16:46:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-array-is-not-working-could-someone-point-out-how-i-can/m-p/868024#M342837</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-04T16:46:30Z</dc:date>
    </item>
    <item>
      <title>Re: My array is not working, could someone point out how i can concatenate these values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-array-is-not-working-could-someone-point-out-how-i-can/m-p/868026#M342839</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/252358"&gt;@Hello_there&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi, the purpose of this exercise is to concatenate these values. I'm still new to arrays, and was wondering if i can receive some help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
infile datalines dsd dlm=",";
	input subject $ apple $ orange $ banana $ grape $ cherry $ jackfruit $;
datalines;
001, Y, , Y, , , Y
002, , , , Y, , Y
003, , , , , , 
;
run;


data want; set have; /* does not work*/
array tmp{*} apple--jackfruit;
	want=catx(", ", of tmp:);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The desired output i need is:&lt;/P&gt;
&lt;P&gt;subject&lt;/P&gt;
&lt;P&gt;001&amp;nbsp;&amp;nbsp;&amp;nbsp; apple, banana, jackfruit&lt;/P&gt;
&lt;P&gt;002&amp;nbsp;&amp;nbsp;&amp;nbsp; grape, jackfruit&lt;/P&gt;
&lt;P&gt;003&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;SAS tells you why it "doesn't work", just read the LOG which will look something like:&lt;/P&gt;
&lt;PRE&gt;78   data want; set have; /* does not work*/
79   array tmp{*} apple--jackfruit;
80      want=catx(", ", of tmp:);
             ----
             71
ERROR 71-185: The CATX function call does not have enough arguments.

81   run;

&lt;/PRE&gt;
&lt;P&gt;Two failures, one is you use a variable list TMP: which doesn't work because you have no variables whose names start with TMP. If you intend to use the &lt;STRONG&gt;values &lt;/STRONG&gt;of the variables in the array the syntax would be:&lt;/P&gt;
&lt;PRE&gt;data want; set have; /* does work for some definitions of "work" */
array tmp{*} apple--jackfruit;
	want=catx(", ", of tmp(*) );
run;&lt;/PRE&gt;
&lt;P&gt;not the (*) following the Array name TMP. That is the way to use all values of the elements of the array, not TMP: .&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 16:50:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-array-is-not-working-could-someone-point-out-how-i-can/m-p/868026#M342839</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-04-04T16:50:14Z</dc:date>
    </item>
    <item>
      <title>Re: My array is not working, could someone point out how i can concatenate these values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-array-is-not-working-could-someone-point-out-how-i-can/m-p/868027#M342840</link>
      <description>&lt;P&gt;This should give you what you are looking for&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile datalines dsd dlm=",";
	input subject $ apple $ orange $ banana $ grape $ cherry $ jackfruit $;
	datalines;
001, Y, , Y, , , Y
002, , , , Y, , Y
003, , , , , , 
;
run;

data want(KEEP= subject want);
	set have;

	/* does not work*/
	length want $100;
	want='';
	array tmp{*} apple--jackfruit;
	do i=1 to dim(tmp);
		want=catx(", ", want,ifc(tmp[i]='Y',vname(tmp[i]),''));
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Apr 2023 16:51:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-array-is-not-working-could-someone-point-out-how-i-can/m-p/868027#M342840</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2023-04-04T16:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: My array is not working, could someone point out how i can concatenate these values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-array-is-not-working-could-someone-point-out-how-i-can/m-p/868028#M342841</link>
      <description>Thanks, Tom!</description>
      <pubDate>Tue, 04 Apr 2023 17:00:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-array-is-not-working-could-someone-point-out-how-i-can/m-p/868028#M342841</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-04-04T17:00:33Z</dc:date>
    </item>
    <item>
      <title>Re: My array is not working, could someone point out how i can concatenate these values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-array-is-not-working-could-someone-point-out-how-i-can/m-p/868029#M342842</link>
      <description>Hey, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; ! Thanks for the explanation and for your help again. Arrays are still tricky for me</description>
      <pubDate>Tue, 04 Apr 2023 17:01:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-array-is-not-working-could-someone-point-out-how-i-can/m-p/868029#M342842</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-04-04T17:01:16Z</dc:date>
    </item>
    <item>
      <title>Re: My array is not working, could someone point out how i can concatenate these values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-array-is-not-working-could-someone-point-out-how-i-can/m-p/868030#M342843</link>
      <description>Thanks for breaking it down for me, ballardw!</description>
      <pubDate>Tue, 04 Apr 2023 17:01:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-array-is-not-working-could-someone-point-out-how-i-can/m-p/868030#M342843</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-04-04T17:01:51Z</dc:date>
    </item>
    <item>
      <title>Re: My array is not working, could someone point out how i can concatenate these values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-array-is-not-working-could-someone-point-out-how-i-can/m-p/868031#M342844</link>
      <description>Thanks for this eloquent solution, could you explain to me the purpose of doing want = "" after the length statement in your code?</description>
      <pubDate>Tue, 04 Apr 2023 17:02:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-array-is-not-working-could-someone-point-out-how-i-can/m-p/868031#M342844</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-04-04T17:02:34Z</dc:date>
    </item>
    <item>
      <title>Re: My array is not working, could someone point out how i can concatenate these values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-array-is-not-working-could-someone-point-out-how-i-can/m-p/868033#M342846</link>
      <description>The Length Statement is executed once during the compilation phase, which in turn, would declare the 'want' variable in the PDV, and assign it a blank.&lt;BR /&gt;&lt;BR /&gt;As you loop through the data set records via the SET statement, you want to make sure to explicitly reset the 'want' variable back to blank, before using in the catx function within the loop.&lt;BR /&gt;&lt;BR /&gt;Hope this helps</description>
      <pubDate>Tue, 04 Apr 2023 17:11:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-array-is-not-working-could-someone-point-out-how-i-can/m-p/868033#M342846</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2023-04-04T17:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: My array is not working, could someone point out how i can concatenate these values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-array-is-not-working-could-someone-point-out-how-i-can/m-p/868035#M342848</link>
      <description>&lt;P&gt;Very helpful, thanks, AhmedAl_Attar!&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 17:13:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-array-is-not-working-could-someone-point-out-how-i-can/m-p/868035#M342848</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-04-04T17:13:18Z</dc:date>
    </item>
  </channel>
</rss>

