<?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: array processing (?) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/array-processing/m-p/407107#M99181</link>
    <description>&lt;P&gt;I have to assume that "get rid of the score" means set it to missing.&amp;nbsp; After all, you can't get rid of a variable on one observation unless you get rid of the variable for all observations&amp;nbsp; So that step might look like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;array names {*}&amp;nbsp; list of all variable names to process here;&lt;/P&gt;
&lt;P&gt;do _n_=1 to dim(names);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if names{_n_} = 1 then names{_n_} = .O;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;else if names{_n_} = 2 then names {_n_} = .T;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That changes the values to missing, but still preserves the original values as being distinct from one another.&amp;nbsp; All the original "1" values are saved as the special missing value .O so you can get the average of all the 3+ values, but retain the knowledge of what the missing values used to be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Stringing together names is rarely a good idea.&amp;nbsp; With that being said, here is how you might modify the DATA step above to do it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;length _3_plus_names $ 500;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;array names {*}&amp;nbsp; list of all variable names to process here;&lt;/P&gt;
&lt;P&gt;do _n_=1 to dim(names);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if names{_n_} = 1 then names{_n_} = .O;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;else if names{_n_} = 2 then names {_n_} = .T;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;FONT color="#FF0000"&gt;else if names{_n_} &amp;gt;= 3 then _3_plus_names = catx(' - ', _3_plus_names, vname(names{_n_})) ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 24 Oct 2017 23:22:45 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-10-24T23:22:45Z</dc:date>
    <item>
      <title>array processing (?)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-processing/m-p/407078#M99167</link>
      <description>&lt;P&gt;my data set has the vars listed below (along with a unique student ID). The values can = . , 1, 2, 3 , 4 or 5. For each observation I only want to keep the scores that are ge 3. Next, I want to create a variable named MET_AP, which will be a string of the names of the exams with a value ge 3 separated by a dash (if more than one occurrence).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Data I Want:&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp;MET_AP&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; APbio2015 - APchem2015&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;APcalcBC2015 -&amp;nbsp;APlit2015 -&amp;nbsp;&amp;nbsp;APphys12015&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;APworldhist2015&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;List of variables with values = . , 1, 2, 3, 4, 5&lt;/P&gt;
&lt;TABLE width="343"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="343"&gt;APbio2015&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="343"&gt;APcalcAB2015&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="343"&gt;APcalcABsub2015&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="343"&gt;APcalcBC2015&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="343"&gt;APchem2015&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="343"&gt;APengl2015&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="343"&gt;APlit2015&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="343"&gt;APenv_scr2015&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="343"&gt;APphysB2015&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="343"&gt;APphys_elect2015&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="343"&gt;APphys_mech2015&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="343"&gt;APphys12015&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="343"&gt;APphys22015&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="343"&gt;APstats2015&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="343"&gt;APworldhist2015&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="343"&gt;APmacro2015&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="343"&gt;APmicro2015&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="343"&gt;APeurohist2015&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="343"&gt;APgovt2015&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="343"&gt;APgovt_US2015&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="343"&gt;APgeogr2015&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="343"&gt;APint_engl2015&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="343"&gt;APhist2015&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2017 21:02:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-processing/m-p/407078#M99167</guid>
      <dc:creator>GreggB</dc:creator>
      <dc:date>2017-10-24T21:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: array processing (?)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-processing/m-p/407107#M99181</link>
      <description>&lt;P&gt;I have to assume that "get rid of the score" means set it to missing.&amp;nbsp; After all, you can't get rid of a variable on one observation unless you get rid of the variable for all observations&amp;nbsp; So that step might look like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;array names {*}&amp;nbsp; list of all variable names to process here;&lt;/P&gt;
&lt;P&gt;do _n_=1 to dim(names);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if names{_n_} = 1 then names{_n_} = .O;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;else if names{_n_} = 2 then names {_n_} = .T;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That changes the values to missing, but still preserves the original values as being distinct from one another.&amp;nbsp; All the original "1" values are saved as the special missing value .O so you can get the average of all the 3+ values, but retain the knowledge of what the missing values used to be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Stringing together names is rarely a good idea.&amp;nbsp; With that being said, here is how you might modify the DATA step above to do it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;length _3_plus_names $ 500;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;array names {*}&amp;nbsp; list of all variable names to process here;&lt;/P&gt;
&lt;P&gt;do _n_=1 to dim(names);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if names{_n_} = 1 then names{_n_} = .O;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;else if names{_n_} = 2 then names {_n_} = .T;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;FONT color="#FF0000"&gt;else if names{_n_} &amp;gt;= 3 then _3_plus_names = catx(' - ', _3_plus_names, vname(names{_n_})) ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2017 23:22:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-processing/m-p/407107#M99181</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-10-24T23:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: array processing (?)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-processing/m-p/407125#M99191</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array scores APbio2015 -- APhist2015;
do i = 1 to dim(scores);
	if scores{i} &amp;gt;= 3 then MET_AP = catx(" - ", MET_AP, vname(scores{i}));
	end;
keep ID MET_AP;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 03:17:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-processing/m-p/407125#M99191</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-10-25T03:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: array processing (?)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-processing/m-p/407184#M99208</link>
      <description>&lt;P&gt;You can use (as already suggested by others) the CATX function to string the names - but I would much prefer to use CALL CATX, for two reasons:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;You get a warning&amp;nbsp;if the output variable is too short to hold the result&lt;/LI&gt;&lt;LI&gt;It is a bit more efficient, CPU-wise&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;So, a solution could be something like this:&lt;/P&gt;&lt;PRE&gt;data want;
  set have;
  array scores(*) APbio2015--APhist2015;
  length MET_AP $300;
  do _N_=1 to dim(scores);
    if scores(_N_)&amp;gt;=3 then
      call catx(' - ',MET_AP,scores(_N_));
    end;
  keep ID MET_AP;
run;  &lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Oct 2017 10:05:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-processing/m-p/407184#M99208</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2017-10-25T10:05:24Z</dc:date>
    </item>
  </channel>
</rss>

