<?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 Adding average column and dropping columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-average-column-and-dropping-columns/m-p/516704#M139591</link>
    <description>&lt;P&gt;I am reading in a data set with the album name and song times in min and sec for each song. I then used an array to find the song time in just minutes for each song. I then want to add a variable for the mean song length of every album and drop the min and sec variables. I have been trying the following code but it is not creating the new mean song length variable nor dropping the other variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATA songs;&lt;BR /&gt;FILENAME webpage URL 'http://people.stat.sc.edu/Hitchcock/beatles_songlengths.txt';&lt;BR /&gt;INFILE webpage ;&lt;BR /&gt;INPUT album_name  $ 1-38 min1 sec1 min2 sec2 min3 sec3 min4 sec4 min5 sec5 min6 sec6 min7 sec7 min8 sec8 min9 sec9 min10 sec10 min11 sec11 min12 sec12 min13 sec13 min14 sec14;&lt;BR /&gt;ARRAY min(14) min1 min2 min3 min4 min5 min6 min7 min8 min9 min10 min11 min12 min13 min14;&lt;BR /&gt;ARRAY sec(14) sec1 sec2 sec3 sec4 sec5 sec6 sec7 sec8 sec9 sec10 sec11 sec12 sec13 sec14;&lt;BR /&gt;ARRAY songtime(14);&lt;BR /&gt;DO i=1 to 14;&lt;BR /&gt;songtime(i)=min(i)+sec(i)/60;&lt;BR /&gt;END;&lt;BR /&gt;RETAIN avgsong;&lt;BR /&gt;avgsong=songtime(i)/i;&lt;BR /&gt;RUN;&lt;BR /&gt;  &lt;BR /&gt;  &lt;BR /&gt;PROC PRINT DATA=songs;&lt;BR /&gt;DROP min(i) sec(i) i;&lt;BR /&gt;RUN;&lt;BR /&gt;  &lt;/PRE&gt;</description>
    <pubDate>Wed, 28 Nov 2018 14:48:19 GMT</pubDate>
    <dc:creator>Steelersgirl</dc:creator>
    <dc:date>2018-11-28T14:48:19Z</dc:date>
    <item>
      <title>Adding average column and dropping columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-average-column-and-dropping-columns/m-p/516704#M139591</link>
      <description>&lt;P&gt;I am reading in a data set with the album name and song times in min and sec for each song. I then used an array to find the song time in just minutes for each song. I then want to add a variable for the mean song length of every album and drop the min and sec variables. I have been trying the following code but it is not creating the new mean song length variable nor dropping the other variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATA songs;&lt;BR /&gt;FILENAME webpage URL 'http://people.stat.sc.edu/Hitchcock/beatles_songlengths.txt';&lt;BR /&gt;INFILE webpage ;&lt;BR /&gt;INPUT album_name  $ 1-38 min1 sec1 min2 sec2 min3 sec3 min4 sec4 min5 sec5 min6 sec6 min7 sec7 min8 sec8 min9 sec9 min10 sec10 min11 sec11 min12 sec12 min13 sec13 min14 sec14;&lt;BR /&gt;ARRAY min(14) min1 min2 min3 min4 min5 min6 min7 min8 min9 min10 min11 min12 min13 min14;&lt;BR /&gt;ARRAY sec(14) sec1 sec2 sec3 sec4 sec5 sec6 sec7 sec8 sec9 sec10 sec11 sec12 sec13 sec14;&lt;BR /&gt;ARRAY songtime(14);&lt;BR /&gt;DO i=1 to 14;&lt;BR /&gt;songtime(i)=min(i)+sec(i)/60;&lt;BR /&gt;END;&lt;BR /&gt;RETAIN avgsong;&lt;BR /&gt;avgsong=songtime(i)/i;&lt;BR /&gt;RUN;&lt;BR /&gt;  &lt;BR /&gt;  &lt;BR /&gt;PROC PRINT DATA=songs;&lt;BR /&gt;DROP min(i) sec(i) i;&lt;BR /&gt;RUN;&lt;BR /&gt;  &lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Nov 2018 14:48:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-average-column-and-dropping-columns/m-p/516704#M139591</guid>
      <dc:creator>Steelersgirl</dc:creator>
      <dc:date>2018-11-28T14:48:19Z</dc:date>
    </item>
    <item>
      <title>Re: Adding average column and dropping columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-average-column-and-dropping-columns/m-p/516734#M139597</link>
      <description>&lt;P&gt;First off, please avoid coding in upper case, it really makes reading code harder.&amp;nbsp; Updated below, note do not use min() as that is a SAS function.&amp;nbsp; I would always - good programming practice - put arrays in curly braces so as to discern them from functions:&lt;/P&gt;
&lt;PRE&gt;filename webpage url 'http://people.stat.sc.edu/Hitchcock/beatles_songlengths.txt';

data songs (keep=album_name avgsong);
  infile webpage;
  retain avgsong;
  input album_name  $ 1-38 min1 sec1 min2 sec2 min3 sec3 min4 sec4 min5 sec5 min6 sec6 min7 sec7 min8 sec8 min9 sec9 min10 sec10 min11 sec11 min12 sec12 min13 sec13 min14 sec14;
  array m{14};
  array s{14};
  array songtime{14};
  do i=1 to 14;
    songtime{i}=m{i}*60+s{i};
  end;
  avgsong=mean(of songtime:);
run;&lt;/PRE&gt;
&lt;P&gt;Also note, you can simplify your code, as it is always min, then sec, by using a two level array:&lt;/P&gt;
&lt;PRE&gt; 
filename webpage url 'http://people.stat.sc.edu/Hitchcock/beatles_songlengths.txt';

data songs;
  infile webpage;
  retain avgsong;
  input album_name  $ 1-38 min1 sec1 min2 sec2 min3 sec3 min4 sec4 min5 sec5 min6 sec6 min7 sec7 min8 sec8 min9 sec9 min10 sec10 min11 sec11 min12 sec12 min13 sec13 min14 sec14;
  array time{14,2} min1--sec14;
  array songtime{14};
  do i=1 to 14;
    songtime{i}=time{i,1}*60+time{i,2};
  end;
  avgsong=mean(of songtime:);
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 15:27:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-average-column-and-dropping-columns/m-p/516734#M139597</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-28T15:27:40Z</dc:date>
    </item>
    <item>
      <title>Re: Adding average column and dropping columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-average-column-and-dropping-columns/m-p/516740#M139600</link>
      <description>&lt;P&gt;instead of&lt;/P&gt;
&lt;P&gt;avgsong=songtime(i)/I;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;try&lt;/P&gt;
&lt;P&gt;avgsong=mean( of songtime(*)); IF you want the average song length per album (record).&lt;/P&gt;
&lt;P&gt;If you want the average song length across all albums you then need to do something else such as Proc Means/Summary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You again to forget to post the ERRORS your code generates. You would get an Array subscript out of range for the line&lt;/P&gt;
&lt;P&gt;avgsong=songtime(i)/I;&lt;/P&gt;
&lt;P&gt;because AFTER the loop the index variable I will have a value of 15.&lt;/P&gt;
&lt;P&gt;If you want to drop a variable put the DROP in the data step, not proc print. That is why you got a message similar to:&lt;/P&gt;
&lt;PRE&gt;NOTE: The DROP and KEEP statements are not supported in procedure steps in this release of the
      SAS System. Therefore, these statements are ignored.
&lt;/PRE&gt;
&lt;P&gt;in the log for proc print. HINT: Read the log. In the data step&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;drop min: sec: i;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you do not want to print the dropped variable(s) either explicitly list the variables you want to print using a VAR statement or use the data set option as&lt;/P&gt;
&lt;P&gt;PROC PRINT DATA=songs (DROP= min: sec: I);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DROP statements or options will &lt;STRONG&gt;not&lt;/STRONG&gt; recognize an array reference and will have an error in the log. The variable list shortcut min: can reference all variables that start with MIN or a range list like drop min1-min14; min(i) is right out.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 15:37:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-average-column-and-dropping-columns/m-p/516740#M139600</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-11-28T15:37:49Z</dc:date>
    </item>
  </channel>
</rss>

