<?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: Macro with Variable-list from rows in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Macro-with-Variable-list-from-rows/m-p/45476#M11958</link>
    <description>Scott's reply is the best in principle. However, accessing the dictionary can be very slow if you have many tables, especially if you have libraries pointing to RDBMS data.&lt;BR /&gt;
To build a list from specific known tables, extracting table metadata directly is faster, if not as clean as querying the dictionary.&lt;BR /&gt;
[pre]&lt;BR /&gt;
%macro makevarlist(table, prefix);&lt;BR /&gt;
  %let varlist=;&lt;BR /&gt;
  %let dsid=%sysfunc(open(&amp;amp;table));&lt;BR /&gt;
  %do i = 1 %to %sysfunc(attrn(&amp;amp;dsid,nvars));&lt;BR /&gt;
    %let varname=%sysfunc(varname(&amp;amp;dsid,&amp;amp;i));&lt;BR /&gt;
    %if %substr(&amp;amp;varname,1,3)=&amp;amp;prefix %then %let varlist=&amp;amp;varlist &amp;amp;varname;&lt;BR /&gt;
  %end;&lt;BR /&gt;
  %let dsid=%sysfunc(close(&amp;amp;dsid));&lt;BR /&gt;
  %put &amp;amp;varlist;&lt;BR /&gt;
%mend;&lt;BR /&gt;
%makevarlist(sashelp.citiwk, WSP)</description>
    <pubDate>Wed, 17 Jun 2009 23:34:07 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2009-06-17T23:34:07Z</dc:date>
    <item>
      <title>Macro with Variable-list from rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-with-Variable-list-from-rows/m-p/45472#M11954</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I want to take some rows as my variable, whitch I put in a macro to Plot it.&lt;BR /&gt;
&lt;BR /&gt;
plot (&amp;amp;yvar.)*xvar&lt;BR /&gt;
&lt;BR /&gt;
But I dont know how I can make it more dynamic. Now I define my yvar manual for each plot (e.g. %plot (yvar=xyz_1 xyz_7 xyz_11 ...). How I can instruct SAS that it take all rows which begin with "xyz_" as yvar ? Maybe do you have an idea? Thanks?&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Lex</description>
      <pubDate>Wed, 17 Jun 2009 09:49:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-with-Variable-list-from-rows/m-p/45472#M11954</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-17T09:49:19Z</dc:date>
    </item>
    <item>
      <title>Re: Macro with Variable-list from rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-with-Variable-list-from-rows/m-p/45473#M11955</link>
      <description>It's a bit unclear what you mean by "take some rows". My guess is that you mean variable/column name. In this case you can use DICTIONARY.COLUMNS, or data step functions to create desired macro variables/calls.&lt;BR /&gt;
&lt;BR /&gt;
If you mean value within a row of data, it doesn't make sense to me. Please attach some sample data to describe your situation better.&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Wed, 17 Jun 2009 11:52:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-with-Variable-list-from-rows/m-p/45473#M11955</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2009-06-17T11:52:54Z</dc:date>
    </item>
    <item>
      <title>Re: Macro with Variable-list from rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-with-Variable-list-from-rows/m-p/45474#M11956</link>
      <description>yes, I mean the name from the variable.&lt;BR /&gt;
&lt;BR /&gt;
(1)&lt;BR /&gt;
v1 v2 xyz_1 xyz_3 xyz_7&lt;BR /&gt;
a  a  2        3        1&lt;BR /&gt;
a  a  2        3        3&lt;BR /&gt;
&lt;BR /&gt;
(2)&lt;BR /&gt;
v1 v2 xyz_2 xyz_4 xyz_5&lt;BR /&gt;
b  b  1        2        1&lt;BR /&gt;
b  b  2        2        2&lt;BR /&gt;
&lt;BR /&gt;
From this I want to create a varlist and give this to macrovaribale.&lt;BR /&gt;
%let varlist1=columnames separated by space; in this case  xyz_1 xyz_3 xyz_7&lt;BR /&gt;
%let varlist2=columnames separated by space; in this case  xyz_2 xyz_4 xyz_5&lt;BR /&gt;
%plot (yvar=&amp;amp;varlist1);&lt;BR /&gt;
%plot (yvar=&amp;amp;varlist2);&lt;BR /&gt;
&lt;BR /&gt;
Lex</description>
      <pubDate>Wed, 17 Jun 2009 12:33:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-with-Variable-list-from-rows/m-p/45474#M11956</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-17T12:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: Macro with Variable-list from rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-with-Variable-list-from-rows/m-p/45475#M11957</link>
      <description>Yes, the DICTIONARY.COLUMNS view will serve you well, using PROC SQL to generate a SAS macro variable using INTO  with the appropriate WHERE clause.&lt;BR /&gt;
&lt;BR /&gt;
Using the Google advanced search argument below, you will find SAS-hosted documentation and supplemental technical/conference papers on this type of topic, available at the SAS support  &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt;  website:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc sql dictionary columns generate code site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 17 Jun 2009 13:18:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-with-Variable-list-from-rows/m-p/45475#M11957</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-06-17T13:18:01Z</dc:date>
    </item>
    <item>
      <title>Re: Macro with Variable-list from rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-with-Variable-list-from-rows/m-p/45476#M11958</link>
      <description>Scott's reply is the best in principle. However, accessing the dictionary can be very slow if you have many tables, especially if you have libraries pointing to RDBMS data.&lt;BR /&gt;
To build a list from specific known tables, extracting table metadata directly is faster, if not as clean as querying the dictionary.&lt;BR /&gt;
[pre]&lt;BR /&gt;
%macro makevarlist(table, prefix);&lt;BR /&gt;
  %let varlist=;&lt;BR /&gt;
  %let dsid=%sysfunc(open(&amp;amp;table));&lt;BR /&gt;
  %do i = 1 %to %sysfunc(attrn(&amp;amp;dsid,nvars));&lt;BR /&gt;
    %let varname=%sysfunc(varname(&amp;amp;dsid,&amp;amp;i));&lt;BR /&gt;
    %if %substr(&amp;amp;varname,1,3)=&amp;amp;prefix %then %let varlist=&amp;amp;varlist &amp;amp;varname;&lt;BR /&gt;
  %end;&lt;BR /&gt;
  %let dsid=%sysfunc(close(&amp;amp;dsid));&lt;BR /&gt;
  %put &amp;amp;varlist;&lt;BR /&gt;
%mend;&lt;BR /&gt;
%makevarlist(sashelp.citiwk, WSP)</description>
      <pubDate>Wed, 17 Jun 2009 23:34:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-with-Variable-list-from-rows/m-p/45476#M11958</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2009-06-17T23:34:07Z</dc:date>
    </item>
  </channel>
</rss>

