<?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 how can i automate list of variables and call them in proc report in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-can-i-automate-list-of-variables-and-call-them-in-proc/m-p/384565#M91848</link>
    <description>&lt;P&gt;I have a list of variables like PRC1, PRC2, SRC1 and SRC2. can i macrovise it so that if in some time there is no SRC2 and only have&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;PRC1, PRC2, SRC1 - i can use in proc report&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 01 Aug 2017 12:11:27 GMT</pubDate>
    <dc:creator>vraj1</dc:creator>
    <dc:date>2017-08-01T12:11:27Z</dc:date>
    <item>
      <title>how can i automate list of variables and call them in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-i-automate-list-of-variables-and-call-them-in-proc/m-p/384565#M91848</link>
      <description>&lt;P&gt;I have a list of variables like PRC1, PRC2, SRC1 and SRC2. can i macrovise it so that if in some time there is no SRC2 and only have&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;PRC1, PRC2, SRC1 - i can use in proc report&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2017 12:11:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-i-automate-list-of-variables-and-call-them-in-proc/m-p/384565#M91848</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2017-08-01T12:11:27Z</dc:date>
    </item>
    <item>
      <title>Re: how can i automate list of variables and call them in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-i-automate-list-of-variables-and-call-them-in-proc/m-p/384567#M91849</link>
      <description>&lt;P&gt;Where do you have this list of variables? In a dataset? Please elaborate further on what you want us to do &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2017 12:14:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-i-automate-list-of-variables-and-call-them-in-proc/m-p/384567#M91849</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-08-01T12:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: how can i automate list of variables and call them in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-i-automate-list-of-variables-and-call-them-in-proc/m-p/384572#M91850</link>
      <description>&lt;P&gt;Your question is a bit vague. &amp;nbsp;As always however there is no need to go down the route of macros, loops over lists of variables etc. &amp;nbsp;Base SAS provides the answer:&lt;/P&gt;
&lt;PRE&gt;proc report data=have;
  columns _all_;
run;&lt;/PRE&gt;
&lt;P&gt;If SRC2 is not in the dataset, it doesn't get reported, if it is then it does.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2017 12:32:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-i-automate-list-of-variables-and-call-them-in-proc/m-p/384572#M91850</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-08-01T12:32:12Z</dc:date>
    </item>
    <item>
      <title>Re: how can i automate list of variables and call them in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-i-automate-list-of-variables-and-call-them-in-proc/m-p/384608#M91858</link>
      <description>&lt;P&gt;Here is one way to go from a list of potential variable names to a list of actual variable names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dsn=sashelp.class ;
%let varlist=PRC1 PRC2 SRC1 SRC2 AGE h:;
%let optsave=%sysfunc(getoption(dkricond));
options dkricond=nowarn;
proc transpose data=&amp;amp;dsn(obs=0 keep=&amp;amp;varlist) ;
  var _all_;
run;
options dkricond=&amp;amp;optsave;
proc sql noprint ;
%let newlist=;
select _name_ into :newlist separated by ' '
from &amp;amp;syslast;
drop table &amp;amp;syslast;
quit;
%put &amp;amp;=newlist;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;NEWLIST=Age Height&lt;/PRE&gt;
&lt;P&gt;So basically it works by eliminating the warnings about variables listed in KEEP statement not existing and then using PROC TRANSPOSE with OBS=0 and KEEP= options to generate a dataset with just the _NAME_ column. &amp;nbsp;It then uses PROC SQL to generate the list of actual names into a new macro variable and deletes the dataset it created.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2017 13:44:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-i-automate-list-of-variables-and-call-them-in-proc/m-p/384608#M91858</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-08-01T13:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: how can i automate list of variables and call them in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-i-automate-list-of-variables-and-call-them-in-proc/m-p/384613#M91859</link>
      <description>&lt;P&gt;Here is another way that simply removes any variables that aren't on your list:&lt;/P&gt;
&lt;PRE&gt;%macro mylist(dataset);
  %global namelist;

  %if %sysfunc(countw(&amp;amp;dataset.)) eq 2 %then %do;
    %let libnme=%scan(&amp;amp;dataset.,1);
    %let dataset=%scan(&amp;amp;dataset.,2);
  %end;
  %else %do;
    %let libnme=work;
  %end;

  proc sql noprint;
    select name into :namelist
      separated by ' '
        from dictionary.columns
          where libname=%upcase("&amp;amp;libnme.") and
                memname=%upcase("&amp;amp;dataset.") and
                %upcase(name) in ('PRC1', 'PRC2', 'SRC1', 'SRC2')
    ;
  quit;
%mend mylist;

data test;
  input PRC1 PRC2 SRC1;
  cards;
1 2 3
4 5 6
;

%mylist(test);

proc print data=test;
  var &amp;amp;namelist.;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2017 13:49:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-i-automate-list-of-variables-and-call-them-in-proc/m-p/384613#M91859</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-08-01T13:49:22Z</dc:date>
    </item>
  </channel>
</rss>

