<?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 all variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Array-all-variables/m-p/245611#M268559</link>
    <description>&lt;P&gt;These codes are awesome!&lt;/P&gt;
&lt;P&gt;Very easy to follow.&lt;/P&gt;
&lt;P&gt;So much thanks.&lt;/P&gt;
&lt;P&gt;HC&lt;/P&gt;</description>
    <pubDate>Sat, 23 Jan 2016 05:29:01 GMT</pubDate>
    <dc:creator>hhchenfx</dc:creator>
    <dc:date>2016-01-23T05:29:01Z</dc:date>
    <item>
      <title>Array all variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-all-variables/m-p/245593#M268554</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a data of 100+ variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to apply the simple operation to all variable: If variable_value &amp;gt;10000 then variable_value=.;&lt;/P&gt;
&lt;P&gt;I dont want to repeat this line for 100+ line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So is there any way to array all variables without listing their name so I can get it done?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, if I have the first 3 variable that should be excluded from the rule , how can I array all except for them. I can list their 3 name for excluding.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HC&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;/P&gt;
&lt;P&gt;input var1 a b c; &lt;BR /&gt;cards;&lt;BR /&gt; 1 10 2 1000000&lt;BR /&gt; 2 10 3 1&lt;BR /&gt; 3 10 4 0&lt;BR /&gt; 4 . 100000 1000000&lt;BR /&gt; 5 100000 1 2&lt;BR /&gt; 6 10 2 300000&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jan 2016 03:19:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-all-variables/m-p/245593#M268554</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2016-01-23T03:19:11Z</dc:date>
    </item>
    <item>
      <title>Re: Array all variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-all-variables/m-p/245597#M268555</link>
      <description>Its easier if it was all, but you could list the first and last with -- to separate them. &lt;BR /&gt;&lt;BR /&gt;Firstvar--lastvar;&lt;BR /&gt;&lt;BR /&gt;Other options include querying the SAS help table vcolumn to get the variable list. Thats been illustrated on the forums quite a bit.</description>
      <pubDate>Sat, 23 Jan 2016 03:54:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-all-variables/m-p/245597#M268555</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-01-23T03:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: Array all variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-all-variables/m-p/245598#M268556</link>
      <description>&lt;P&gt;I am not sure if it is possible for us to do the arrays without the variable names. We need the variable names in arrays. However, alternatively what we could do is we could get the list of all other variable names &amp;nbsp;except the names which are not required (3 variable what you mentioned) into a macro variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;after you create the dataset with all the variables and data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;write&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;select distinct name into : vars separated by ' ' from dictionary.columns where memname='dataset name' and name not in ('x1','x2','x3');&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;select count(distinct name) into : cnt&amp;nbsp;from dictionary.columns where memname='dataset name' and name not in ('x1','x2','x3');&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;we get list of all variable names excluding the three variables into vars macro variable separated by blank space. In teh cnt macro variable we get the number of variable count.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;then write the arrays as below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data arrays;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;array vr(&amp;amp;cnt) &amp;amp;vars;&lt;/P&gt;
&lt;P&gt;do i = 1 to &amp;amp;cnt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If vr(i) &amp;gt;10000 then vr(i)=.;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jan 2016 03:59:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-all-variables/m-p/245598#M268556</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2016-01-23T03:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: Array all variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-all-variables/m-p/245601#M268557</link>
      <description>&lt;P&gt;If the list of variables is fairly long and the list of excluded variables is short, it would be simpler to list the latter explicitly. For example, to exclude &lt;STRONG&gt;var1&lt;/STRONG&gt; and &lt;STRONG&gt;b&lt;/STRONG&gt; :&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 _v{*} _numeric_;
do _i = 1 to dim(_v);
    if upcase(vname(_v{_i})) not in ("VAR1", "B") then
	   if _v{_i} &amp;gt; 10000 then call missing(_v{_i});
	end;
drop _i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Jan 2016 04:16:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-all-variables/m-p/245601#M268557</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-01-23T04:16:00Z</dc:date>
    </item>
    <item>
      <title>Re: Array all variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-all-variables/m-p/245607#M268558</link>
      <description>&lt;P&gt;If they really are the first three variables then just index over the array starting with the index set to 4.&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 _all _numeric_;
  do _n_=4 to dim(_all);
     if _all(_n_) &amp;gt; 10000 then _all(_n_)=.;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If they aren't the first three, you can make them the first three by adding another SET statement with a KEEP= option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have(keep=var1 var2 var3);
  set have;
  array _all _numeric_;
  do _n_=4 to dim(_all);
     if _all(_n_) &amp;gt; 10000 then _all(_n_)=.;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Jan 2016 04:48:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-all-variables/m-p/245607#M268558</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-01-23T04:48:22Z</dc:date>
    </item>
    <item>
      <title>Re: Array all variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-all-variables/m-p/245611#M268559</link>
      <description>&lt;P&gt;These codes are awesome!&lt;/P&gt;
&lt;P&gt;Very easy to follow.&lt;/P&gt;
&lt;P&gt;So much thanks.&lt;/P&gt;
&lt;P&gt;HC&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jan 2016 05:29:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-all-variables/m-p/245611#M268559</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2016-01-23T05:29:01Z</dc:date>
    </item>
    <item>
      <title>Re: Array all variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-all-variables/m-p/245627#M268560</link>
      <description>&lt;P&gt;If it is important to keep the variables in order as in&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats﻿&lt;/a&gt;&amp;nbsp;program does you can alternatevly built the variable list explicitly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input var1 a b c; 
   var3 = _n_*10;
   d = a;  
   var2 = var1*10;  
   cards;
1 10 2 1000000
2 10 3 1
3 10 4 0
4 . 100000 1000000
5 100000 1 2
6 10 2 300000
   run;
proc print;
   run;
proc transpose data=have(obs=0 drop=var: keep=_numeric_) out=vars;
   run;
proc sql noprint;
   select nliteral(_name_) into :varlist separated by ' ' from vars;
   quit;
%put NOTE: &amp;amp;=varlist;

data change;
   set have;
   array _x[*] &amp;amp;varlist;
   do _n_ = 1 to dim(_x);
      if _x[_n_] ge 1e5 then _x[_n_]=.;
      end;
   run;
proc print;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/1564i45C913A05744F044/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jan 2016 19:04:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-all-variables/m-p/245627#M268560</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-01-23T19:04:02Z</dc:date>
    </item>
  </channel>
</rss>

