<?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: Non-referenced array elements not dropped by a drop command in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Non-referenced-array-elements-not-dropped-by-a-drop-command/m-p/752920#M237217</link>
    <description>&lt;P&gt;You really should show the entire data step. You do not show a DROP statement or option anywhere, so can't address why not.&lt;/P&gt;
&lt;P&gt;You don't actually show where Lec16_2 or Lec16_5 might be used. You do not create them, they are not shown in your array statement. Your Array has&lt;/P&gt;
&lt;PRE&gt;A3LEC16_1-A3LEC16_7&lt;/PRE&gt;
&lt;P&gt;Not Lec16_2 or Lec16_5. So you did you intent to reference A3Lec16_2???? &lt;/P&gt;</description>
    <pubDate>Thu, 08 Jul 2021 16:26:26 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-07-08T16:26:26Z</dc:date>
    <item>
      <title>Non-referenced array elements not dropped by a drop command</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Non-referenced-array-elements-not-dropped-by-a-drop-command/m-p/752908#M237208</link>
      <description>&lt;P&gt;I define a 7-element array and put a value in one or more of the elements but never two of them. (Why you say. Because LEC16 (see code) by design never includes a value for i1=2 or 5.) I later drop those two elements. But, i get a warning that those two elements were never addressed and the elements are not dropped. I understand the warning as useful but why weren't the elements dropped? Here's the code for one of the arrays. The drop command that follows is just drop&amp;nbsp; LEC16_2 LEC16_5;&lt;/P&gt;&lt;PRE&gt;*	LEC_16;
    array vlec16{7} A3LEC16_1-A3LEC16_7;
	nlen=lengthn(LEC_16);
	if (nlen ge 1) then do;
	nlen=1+(nlen-1)/2;
    do i=1 to nlen;
	   i1=1+2*(i-1);
	   val=substr(LEC_16,i1,1);
       vlec16{input(val,BEST32.)}=1;
    end;
	end;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jul 2021 15:57:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Non-referenced-array-elements-not-dropped-by-a-drop-command/m-p/752908#M237208</guid>
      <dc:creator>emaguin</dc:creator>
      <dc:date>2021-07-08T15:57:51Z</dc:date>
    </item>
    <item>
      <title>Re: Non-referenced array elements not dropped by a drop command</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Non-referenced-array-elements-not-dropped-by-a-drop-command/m-p/752920#M237217</link>
      <description>&lt;P&gt;You really should show the entire data step. You do not show a DROP statement or option anywhere, so can't address why not.&lt;/P&gt;
&lt;P&gt;You don't actually show where Lec16_2 or Lec16_5 might be used. You do not create them, they are not shown in your array statement. Your Array has&lt;/P&gt;
&lt;PRE&gt;A3LEC16_1-A3LEC16_7&lt;/PRE&gt;
&lt;P&gt;Not Lec16_2 or Lec16_5. So you did you intent to reference A3Lec16_2???? &lt;/P&gt;</description>
      <pubDate>Thu, 08 Jul 2021 16:26:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Non-referenced-array-elements-not-dropped-by-a-drop-command/m-p/752920#M237217</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-08T16:26:26Z</dc:date>
    </item>
    <item>
      <title>Re: Non-referenced array elements not dropped by a drop command</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Non-referenced-array-elements-not-dropped-by-a-drop-command/m-p/752962#M237236</link>
      <description>Thanks for your reply. My assumption of array x{3} x1-x3; is that three new variables are created, x1, x2, x3. That the execution of the array statement creates them, not that do i=1 to 3; x{i}=5; creates them. Furthermore, I just re-ran code block minus the drop statement and looked at the variable list in the file and those variables are in there.&lt;BR /&gt;The entire data step is about 190 lines long. It consists of those 11 lines repeated 16 times for LEC_1 to LEC_16 plus some comment lines. The drop is just a drop but here it is:&lt;BR /&gt;drop LEC_1 LEC_2 LEC_3 LEC_4 LEC_5 LEC_6 LEC_7 LEC_8 LEC_9 LEC_10&lt;BR /&gt;LEC_11 LEC_12 LEC_13 LEC_14 LEC_15 LEC_16 val i i1&lt;BR /&gt;LEC1_2 LEC1_5 LEC2_2 LEC2_5 LEC3_2 LEC3_5 LEC4_2 LEC4_5 LEC5_2 LEC5_5&lt;BR /&gt;LEC6_2 LEC6_5 LEC7_2 LEC7_5 LEC8_2 LEC8_5 LEC9_2 LEC9_5 LEC10_2 LEC10_5&lt;BR /&gt;LEC11_2 LEC11_5 LEC12_2 LEC12_5 LEC13_2 LEC13_5 LEC14_2 LEC14_5&lt;BR /&gt;LEC15_2 LEC15_5 LEC16_2 LEC16_5;&lt;BR /&gt;&lt;BR /&gt;Background. LEC_(i) records responses to an all-the-apply type question. There are five possible values, 1,3,4,6,7, but because of the all-that-apply element, LEC_(i) may equal 3 but it may also equal 1,3,4,5,6,7. That little bit of code unpacks LEC_(i) and records the string values as numeric in their own variables: LEC(i)_1, LEC(i)_3, LEC(i)_4, LEC(i)_6, LEC(i)_7.&lt;BR /&gt;I could have said array vlec16{5} A3LEC15_1 A3LEC15_3 A3LEC15_4 A3LEC15_6 A3LEC15_7; but why?? It's simpler to do what I did and then not use two of the variables and then delete them. So what! Like I said, understand the warning. But why did sas not execute the statement? It was a warning not an error.&lt;BR /&gt;Gene Maguin&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 08 Jul 2021 18:13:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Non-referenced-array-elements-not-dropped-by-a-drop-command/m-p/752962#M237236</guid>
      <dc:creator>emaguin</dc:creator>
      <dc:date>2021-07-08T18:13:36Z</dc:date>
    </item>
    <item>
      <title>Re: Non-referenced array elements not dropped by a drop command</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Non-referenced-array-elements-not-dropped-by-a-drop-command/m-p/752997#M237256</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/273054"&gt;@emaguin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I could have said array vlec16{5} A3LEC15_1 A3LEC15_3 A3LEC15_4 A3LEC15_6 A3LEC15_7; but why?? It's simpler to do what I did and then not use two of the variables and then delete them. So what! Like I said, understand the warning. But why did sas not execute the statement? It was a warning not an error.&lt;BR /&gt;Gene Maguin&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Because you did not "drop" A3Lec15_2 (or A3Lec16_2) you said the problem was with Lec16_2. You are now using different variable names than shown in your previous code snippet (A3Lec15). Which is one reason I asked for the entire data step, to see what you may be creating during the data step, exactly what you are "dropping". I strongly suspect you didn't create the variables that you claimed to attempt to drop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A couple of other ways to parse comma delimited string of values and get a 1 or 1/0 coded variable.&lt;/P&gt;
&lt;PRE&gt;data example;
   infile datalines truncover;
   input string $15.;
   array v(7);
   do i=1 to countw(string,',');
      v[input(scan(string,i,','),f8.)]=1;
   end;
datalines;
1
1,3
3,4,7
1,3,7
1,3,4,6,7
;

/* or to do 1/0 coding*/
data example;
   infile datalines truncover;
   input string $15.;
   array v(7);
   do i=1 to 7;
      v[i]= index(string,put(i,f1.))&amp;gt;0;
   end;
datalines;
1
1,3
3,4,7
1,3,7
1,3,4,6,7
;


&lt;/PRE&gt;
&lt;P&gt;Scan can pull a specific position number of a value from a delimited string. The last parameter is a list of delimiters. Lots simpler than trying to use the length and an offset. Probably not needed but sometimes you&amp;nbsp; want to break up a string at different points and though it appropriate to include a specific delimiter in this example. The Index function returns a position in a string of a substring. SAS returns 1 for true or 0 for false with comparing the returned value from Index to &amp;gt; 0.&lt;/P&gt;
&lt;P&gt;Index would not be appropriate for finding 1 if you might have values like 10, 11 or 101 though INDEXW or FINDW might.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I prefer 1/0 coded values for "any that apply" type questions because then a sum=total number of selections, mean=percentage of respondents that selected the choice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW, 190 lines isn't particularly long for a data step.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jul 2021 20:03:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Non-referenced-array-elements-not-dropped-by-a-drop-command/m-p/752997#M237256</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-08T20:03:29Z</dc:date>
    </item>
  </channel>
</rss>

