<?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: Help with using macrovariables to filter observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58177#M12620</link>
    <description>Well I managed to solve my problem, using an example in the sas documentation:&lt;BR /&gt;
&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
   select count(distinct type)&lt;BR /&gt;
      into :n&lt;BR /&gt;
      from sql.features;&lt;BR /&gt;
   select distinct type&lt;BR /&gt;
      into :type1 - :type%left(&amp;amp;n)&lt;BR /&gt;
      from sql.features;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
%macro makeds;&lt;BR /&gt;
   %do i=1 %to &amp;amp;n;&lt;BR /&gt;
      data &amp;amp;&amp;amp;type&amp;amp;i (drop=type);&lt;BR /&gt;
         set sql.features;&lt;BR /&gt;
         if type="&amp;amp;&amp;amp;type&amp;amp;i";&lt;BR /&gt;
      run;&lt;BR /&gt;
   %end;&lt;BR /&gt;
%mend makeds;&lt;BR /&gt;
%makeds;</description>
    <pubDate>Thu, 28 Apr 2011 13:02:22 GMT</pubDate>
    <dc:creator>Longduration</dc:creator>
    <dc:date>2011-04-28T13:02:22Z</dc:date>
    <item>
      <title>Help with using macrovariables to filter observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58172#M12615</link>
      <description>Hello&lt;BR /&gt;
&lt;BR /&gt;
I have a column in a data set that contains multiple values. I'd like to filter this column for x number of different values. my code below works but it only does it for the last value. I've tried to use DO etc to cycle through each value but I've failed..&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL;&lt;BR /&gt;
SELECT cOUNT (*) INTO COUNT&lt;BR /&gt;
FROM TEST.DATABASE.&lt;BR /&gt;
QUIT;&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL;&lt;BR /&gt;
SELECT VARIABLES&lt;BR /&gt;
INTO :VARIABLES1-:VARIABLES%TRIM(%LEFT&amp;amp;COUNT))&lt;BR /&gt;
FROM TEST.DATABASE;&lt;BR /&gt;
QUIT;&lt;BR /&gt;
&lt;BR /&gt;
%MACRO TESTING;&lt;BR /&gt;
&lt;BR /&gt;
DATA TEST.FILTERED;&lt;BR /&gt;
SET TEST.ORIGINAL;&lt;BR /&gt;
&lt;BR /&gt;
WHERE (VARIABLES CONTAINS "&amp;amp;VARIABLES");&lt;BR /&gt;
RUN;&lt;BR /&gt;
%MEND TESTING;&lt;BR /&gt;
%TESTING</description>
      <pubDate>Wed, 27 Apr 2011 12:41:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58172#M12615</guid>
      <dc:creator>Longduration</dc:creator>
      <dc:date>2011-04-27T12:41:22Z</dc:date>
    </item>
    <item>
      <title>Re: Help with using macrovariables to filter observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58173#M12616</link>
      <description>Hello Longdiratuon,&lt;BR /&gt;
If I understood you correctly this is a solution:&lt;BR /&gt;
[pre]&lt;BR /&gt;
PROC SQL;&lt;BR /&gt;
  SELECT VARIABLES&lt;BR /&gt;
  INTO :VALUELIST separated by ","&lt;BR /&gt;
  FROM TEST.DATABASE&lt;BR /&gt;
;QUIT;&lt;BR /&gt;
DATA TEST.FILTERED;&lt;BR /&gt;
   SET TEST.ORIGINAL;&lt;BR /&gt;
   WHERE (VARIABLES in (&amp;amp;VALUELIST);&lt;BR /&gt;
RUN;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Wed, 27 Apr 2011 14:17:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58173#M12616</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-04-27T14:17:27Z</dc:date>
    </item>
    <item>
      <title>Re: Help with using macrovariables to filter observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58174#M12617</link>
      <description>I read your request slightly differently than SPR did.  Does the following example match the scenario you describe?:&lt;BR /&gt;
[pre]&lt;BR /&gt;
&lt;BR /&gt;
data database;&lt;BR /&gt;
  input variables $;&lt;BR /&gt;
  cards;&lt;BR /&gt;
James&lt;BR /&gt;
Judy&lt;BR /&gt;
Robert&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL noprint;&lt;BR /&gt;
  SELECT "variables contains "||quote(strip(VARIABLES))&lt;BR /&gt;
    INTO :VARIABLES separated by " or "&lt;BR /&gt;
      FROM DATABASE;&lt;BR /&gt;
QUIT;&lt;BR /&gt;
&lt;BR /&gt;
data testfile;&lt;BR /&gt;
  length variables $30;&lt;BR /&gt;
  SET sashelp.class (rename=(name=variables));&lt;BR /&gt;
  if variables eq "Jeffrey" then&lt;BR /&gt;
   variables="Jeffrey Al James";&lt;BR /&gt;
  else if variables eq "Philip" then&lt;BR /&gt;
   variables="Judy Robert Philip";&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
DATA FILTERED;&lt;BR /&gt;
  SET testfile;&lt;BR /&gt;
  WHERE &amp;amp;VARIABLES;&lt;BR /&gt;
RUN;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Art</description>
      <pubDate>Wed, 27 Apr 2011 18:48:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58174#M12617</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-04-27T18:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: Help with using macrovariables to filter observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58175#M12618</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure if the so-called global macro variable array is necessary. You can filter it simply with the where statement like below:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG style="color: #000080; font-size: 9pt; font-family: Courier New;"&gt;proc&lt;/STRONG&gt;&lt;SPAN style="font-family: Courier New; font-size: 9pt;"&gt; &lt;/SPAN&gt;&lt;STRONG style="color: #000080; font-size: 9pt; font-family: Courier New;"&gt;sql&lt;/STRONG&gt;&lt;SPAN style="font-family: Courier New; font-size: 9pt;"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: Courier New; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-family: Courier New; font-size: 9pt;"&gt;/* a la TEST.DATABASE */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: Courier New; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-family: Courier New; font-size: 9pt;"&gt;create&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; font-size: 9pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-family: Courier New; font-size: 9pt;"&gt;table&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; font-size: 9pt;"&gt; names &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-family: Courier New; font-size: 9pt;"&gt;as&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: Courier New; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-family: Courier New; font-size: 9pt;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; font-size: 9pt;"&gt; name &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: Courier New; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-family: Courier New; font-size: 9pt;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; font-size: 9pt;"&gt; sashelp.class&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: Courier New; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-family: Courier New; font-size: 9pt;"&gt;where&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; font-size: 9pt;"&gt; name eqt &lt;/SPAN&gt;&lt;SPAN style="color: #800080; font-family: Courier New; font-size: 9pt;"&gt;'A'&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; font-size: 9pt;"&gt;;&lt;/SPAN&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;SPAN style="font-family: Courier New; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-family: Courier New; font-size: 9pt;"&gt;/* a la&amp;nbsp; TEST.FILTERED */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: Courier New; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-family: Courier New; font-size: 9pt;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; font-size: 9pt;"&gt; *&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: Courier New; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-family: Courier New; font-size: 9pt;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; font-size: 9pt;"&gt;&amp;nbsp; sashelp.class&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: Courier New; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-family: Courier New; font-size: 9pt;"&gt;where&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; font-size: 9pt;"&gt; name &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-family: Courier New; font-size: 9pt;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; font-size: 9pt;"&gt; (&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-family: Courier New; font-size: 9pt;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; font-size: 9pt;"&gt; name &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-family: Courier New; font-size: 9pt;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; font-size: 9pt;"&gt; names);&lt;/SPAN&gt;&lt;BR /&gt;&lt;STRONG style="color: #000080; font-size: 9pt; font-family: Courier New;"&gt;quit&lt;/STRONG&gt;&lt;SPAN style="font-family: Courier New; font-size: 9pt;"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #008000; font-family: Courier New; font-size: 9pt;"&gt;/* on lst&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #008000; font-family: Courier New; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sex&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Age&amp;nbsp;&amp;nbsp;&amp;nbsp; Height&amp;nbsp;&amp;nbsp;&amp;nbsp; Weight&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #008000; font-family: Courier New; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; Alfred&amp;nbsp;&amp;nbsp;&amp;nbsp; M&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 14&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 69&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 112.5&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #008000; font-family: Courier New; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp; Alice&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; F&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 13&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 56.5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 84&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #008000; font-family: Courier New; font-size: 9pt;"&gt;*/&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Apr 2011 19:13:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58175#M12618</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2011-04-27T19:13:01Z</dc:date>
    </item>
    <item>
      <title>Re: Help with using macrovariables to filter observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58176#M12619</link>
      <description>Thanks for your responses.&lt;BR /&gt;
&lt;BR /&gt;
I think SPR you're along the lines of what Im trying to do. But with your code, similar to the other suggestions, only seem to work with one variable (?). &lt;BR /&gt;
&lt;BR /&gt;
I would like to automise it so as not to manually type in the code WHERE NAME =xx etc. The person running the program just has to change which variables they want in the external file. &lt;BR /&gt;
&lt;BR /&gt;
By luck, Ive found a sample code that does what I want but I can't change the output to my library rather than 'work' . It splits the data set into individual files corresponding to each variable thats specified. &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%MACRO SPLIT.&lt;BR /&gt;
PROC SQL.&lt;BR /&gt;
SELECT VARIABLE FROM TEST.DATABASE;&lt;BR /&gt;
SELECT VARIABLE&lt;BR /&gt;
INTO: VARIABLE1 -:VARIABLE&amp;amp;SQLOBS.&lt;BR /&gt;
FROM TEST.DATABASE;&lt;BR /&gt;
QUIT;&lt;BR /&gt;
&lt;BR /&gt;
DATA &lt;BR /&gt;
%DO i=1 %TO &amp;amp;SQLOBS; &amp;amp;&amp;amp;VARIABLE&amp;amp;i %END; ;&lt;BR /&gt;
SET TEST.ORIGINAL;&lt;BR /&gt;
SELECT (COLUMNx);&lt;BR /&gt;
&lt;BR /&gt;
%DO j=1 %TO &amp;amp;SQLOBS;&lt;BR /&gt;
WHEN ("&amp;amp;&amp;amp;VARIABLE&amp;amp;j") OUTPUT &amp;amp;&amp;amp;VARIABLE&amp;amp;j;&lt;BR /&gt;
%END;&lt;BR /&gt;
OTHERWISE;&lt;BR /&gt;
END;&lt;BR /&gt;
&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
%MEND;&lt;BR /&gt;
%SPLIT;</description>
      <pubDate>Thu, 28 Apr 2011 09:16:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58176#M12619</guid>
      <dc:creator>Longduration</dc:creator>
      <dc:date>2011-04-28T09:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Help with using macrovariables to filter observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58177#M12620</link>
      <description>Well I managed to solve my problem, using an example in the sas documentation:&lt;BR /&gt;
&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
   select count(distinct type)&lt;BR /&gt;
      into :n&lt;BR /&gt;
      from sql.features;&lt;BR /&gt;
   select distinct type&lt;BR /&gt;
      into :type1 - :type%left(&amp;amp;n)&lt;BR /&gt;
      from sql.features;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
%macro makeds;&lt;BR /&gt;
   %do i=1 %to &amp;amp;n;&lt;BR /&gt;
      data &amp;amp;&amp;amp;type&amp;amp;i (drop=type);&lt;BR /&gt;
         set sql.features;&lt;BR /&gt;
         if type="&amp;amp;&amp;amp;type&amp;amp;i";&lt;BR /&gt;
      run;&lt;BR /&gt;
   %end;&lt;BR /&gt;
%mend makeds;&lt;BR /&gt;
%makeds;</description>
      <pubDate>Thu, 28 Apr 2011 13:02:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58177#M12620</guid>
      <dc:creator>Longduration</dc:creator>
      <dc:date>2011-04-28T13:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: Help with using macrovariables to filter observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58178#M12621</link>
      <description>Don't take this wrong, but I'm totally confused as to which problem you solved other than that you figured out how to use the combination of proc sql and macro code to create multiple files for each unique value in a dataset.&lt;BR /&gt;
&lt;BR /&gt;
That was not how you had originally described the problem you needed to solve and I don't know how obtaining those files solves your original problem.&lt;BR /&gt;
&lt;BR /&gt;
In your initial post you stated: "I have a column in a data set that contains multiple values. I'd like to filter this column for x number of different values."&lt;BR /&gt;
&lt;BR /&gt;
You then provided an example where you had two files, labeled test.database and test.original, and you indicated that you were trying to create a third file labeled test.filtered.&lt;BR /&gt;
&lt;BR /&gt;
I rewrote my original proposed solution so that it creates and uses an include file instead of a macro variable, but I'm not going to post it unless it actually addresses the problem you are trying to solve.&lt;BR /&gt;
&lt;BR /&gt;
I'd be interested in finding out the true nature of the problem you feel that you've solved and how obtaining the files you described solves it.&lt;BR /&gt;
&lt;BR /&gt;
Art</description>
      <pubDate>Thu, 28 Apr 2011 14:42:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58178#M12621</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-04-28T14:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: Help with using macrovariables to filter observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58179#M12622</link>
      <description>Apologies if my problem wasn't clear. Hopefully this is better:&lt;BR /&gt;
&lt;BR /&gt;
----------------------------------------------------------------------------------------------------------&lt;BR /&gt;
Original file that is to be filtered by column "TYPE" using the variables in TEST.DATABASE:&lt;BR /&gt;
&lt;BR /&gt;
TEST.ORIGINAL&lt;BR /&gt;
&lt;BR /&gt;
Column1 Column2 TYPE Column4&lt;BR /&gt;
x x A x&lt;BR /&gt;
x x G x&lt;BR /&gt;
x x B x&lt;BR /&gt;
x x D x&lt;BR /&gt;
x x C x&lt;BR /&gt;
&lt;BR /&gt;
----------------------------------------------------------------------------------------------------------&lt;BR /&gt;
File with variables that are used to filter the column "TYPE" in TEST.ORIGINAL:&lt;BR /&gt;
&lt;BR /&gt;
TEST.DATABASE&lt;BR /&gt;
&lt;BR /&gt;
Variables&lt;BR /&gt;
A,&lt;BR /&gt;
B,&lt;BR /&gt;
C,&lt;BR /&gt;
&lt;BR /&gt;
----------------------------------------------------------------------------------------------------------&lt;BR /&gt;
Resulting in a file with observations only where "TYPE" contains the variables specified earlier:&lt;BR /&gt;
&lt;BR /&gt;
TEST.FILTERED&lt;BR /&gt;
&lt;BR /&gt;
Column1, Column2, TYPE, Column3&lt;BR /&gt;
x,x,A,x&lt;BR /&gt;
x,x,B,x&lt;BR /&gt;
x,x,C,x&lt;BR /&gt;
&lt;BR /&gt;
----------------------------------------------------------------------------------------------------------&lt;BR /&gt;
&lt;BR /&gt;
The following code solves this except it produces an individual file (TEST.A &lt;BR /&gt;
TEST.B and TEST.C for each variable and not a single file as I had originally wanted (DATA.FILTERED): &lt;BR /&gt;
&lt;BR /&gt;
----------------------------------------------------------------------------------------------------------&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL&lt;BR /&gt;
SELECT COUNT (VARIABLES) &lt;BR /&gt;
INTO :n&lt;BR /&gt;
FROM TEST.DATABASE;&lt;BR /&gt;
QUIT;&lt;BR /&gt;
&lt;BR /&gt;
%MACRO FORUM;&lt;BR /&gt;
&lt;BR /&gt;
%DO i=1 %TO &amp;amp;n;&lt;BR /&gt;
DATA TEST.&amp;amp;&amp;amp;VARIABLES&amp;amp;i;&lt;BR /&gt;
SET TEST.ORIGINAL;&lt;BR /&gt;
IF TYPE="&amp;amp;&amp;amp;VARIABLES&amp;amp;i";&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
%END;&lt;BR /&gt;
%MEND;&lt;BR /&gt;
%FORUM;&lt;BR /&gt;
&lt;BR /&gt;
----------------------------------------------------------------------------------------------------------&lt;BR /&gt;
&lt;BR /&gt;
Art, if you have alternative solution I would still appreciate reading it.&lt;BR /&gt;
&lt;BR /&gt;
Thanks</description>
      <pubDate>Thu, 28 Apr 2011 16:03:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58179#M12622</guid>
      <dc:creator>Longduration</dc:creator>
      <dc:date>2011-04-28T16:03:09Z</dc:date>
    </item>
    <item>
      <title>Re: Help with using macrovariables to filter observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58180#M12623</link>
      <description>Longduration,&lt;BR /&gt;
&lt;BR /&gt;
First, a question about test.database.  What does it really look like?  From your example, it might have three records which contain 3 values separated by commas, of it might have three records, each with a value and, possibly, a comma.  Not clear.&lt;BR /&gt;
&lt;BR /&gt;
From your original post, I had thought that test.database looked like:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data test.database;&lt;BR /&gt;
  informat variables $10.;&lt;BR /&gt;
  input variables &amp;amp;;&lt;BR /&gt;
  datalines;&lt;BR /&gt;
A B C&lt;BR /&gt;
E&lt;BR /&gt;
G H&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
In order to provide a solution, we have to know for sure what that file actually looks like.&lt;BR /&gt;
&lt;BR /&gt;
Art&lt;BR /&gt;
&amp;gt; Apologies if my problem wasn't clear. Hopefully this&lt;BR /&gt;
&amp;gt; is better:&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; ------------------------------------------------------&lt;BR /&gt;
&amp;gt; ----------------------------------------------------&lt;BR /&gt;
&amp;gt; Original file that is to be filtered by column "TYPE"&lt;BR /&gt;
&amp;gt; using the variables in TEST.DATABASE:&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; TEST.ORIGINAL&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Column1 Column2 TYPE Column4&lt;BR /&gt;
&amp;gt; x x A x&lt;BR /&gt;
&amp;gt; x x G x&lt;BR /&gt;
&amp;gt; x x B x&lt;BR /&gt;
&amp;gt; x x D x&lt;BR /&gt;
&amp;gt; x x C x&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; ------------------------------------------------------&lt;BR /&gt;
&amp;gt; ----------------------------------------------------&lt;BR /&gt;
&amp;gt; File with variables that are used to filter the&lt;BR /&gt;
&amp;gt; column "TYPE" in TEST.ORIGINAL:&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; TEST.DATABASE&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Variables&lt;BR /&gt;
&amp;gt; A,&lt;BR /&gt;
&amp;gt; B,&lt;BR /&gt;
&amp;gt; C,&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; ------------------------------------------------------&lt;BR /&gt;
&amp;gt; ----------------------------------------------------&lt;BR /&gt;
&amp;gt; Resulting in a file with observations only where&lt;BR /&gt;
&amp;gt; "TYPE" contains the variables specified earlier:&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; TEST.FILTERED&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Column1, Column2, TYPE, Column3&lt;BR /&gt;
&amp;gt; x,x,A,x&lt;BR /&gt;
&amp;gt; x,x,B,x&lt;BR /&gt;
&amp;gt; x,x,C,x&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; ------------------------------------------------------&lt;BR /&gt;
&amp;gt; ----------------------------------------------------&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; The following code solves this except it produces an&lt;BR /&gt;
&amp;gt; individual file (TEST.A &lt;BR /&gt;
&amp;gt; TEST.B and TEST.C for each variable and not a single&lt;BR /&gt;
&amp;gt; file as I had originally wanted (DATA.FILTERED): &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; ------------------------------------------------------&lt;BR /&gt;
&amp;gt; ----------------------------------------------------&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; PROC SQL&lt;BR /&gt;
&amp;gt; SELECT COUNT (VARIABLES) &lt;BR /&gt;
&amp;gt; INTO :n&lt;BR /&gt;
&amp;gt; FROM TEST.DATABASE;&lt;BR /&gt;
&amp;gt; QUIT;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; %MACRO FORUM;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; %DO i=1 %TO &amp;amp;n;&lt;BR /&gt;
&amp;gt; DATA TEST.&amp;amp;&amp;amp;VARIABLES&amp;amp;i;&lt;BR /&gt;
&amp;gt; SET TEST.ORIGINAL;&lt;BR /&gt;
&amp;gt; IF TYPE="&amp;amp;&amp;amp;VARIABLES&amp;amp;i";&lt;BR /&gt;
&amp;gt; RUN;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; %END;&lt;BR /&gt;
&amp;gt; %MEND;&lt;BR /&gt;
&amp;gt; %FORUM;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; ------------------------------------------------------&lt;BR /&gt;
&amp;gt; ----------------------------------------------------&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Art, if you have alternative solution I would still&lt;BR /&gt;
&amp;gt; appreciate reading it.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Thanks</description>
      <pubDate>Thu, 28 Apr 2011 17:14:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58180#M12623</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-04-28T17:14:20Z</dc:date>
    </item>
    <item>
      <title>Re: Help with using macrovariables to filter observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58181#M12624</link>
      <description>The file does actually look exactly as I've posted. It has the column name (Variables), with values separated by a comma. The number of values in this column can be changed (A,B,C,D etc) but they remain separated by a comma  :&lt;BR /&gt;
&lt;BR /&gt;
e.g &lt;BR /&gt;
&lt;BR /&gt;
Variables&lt;BR /&gt;
A,&lt;BR /&gt;
B,&lt;BR /&gt;
C,&lt;BR /&gt;
&lt;BR /&gt;
It is simply just these lines, in order for a person to put what values they would want to filter in this external file without having to go into the code to specify them.</description>
      <pubDate>Thu, 28 Apr 2011 19:32:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58181#M12624</guid>
      <dc:creator>Longduration</dc:creator>
      <dc:date>2011-04-28T19:32:25Z</dc:date>
    </item>
    <item>
      <title>Re: Help with using macrovariables to filter observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58182#M12625</link>
      <description>Longduration,&lt;BR /&gt;
&lt;BR /&gt;
It's still not crystal clear, but I think answering one question will clarify it.  Which of the following two examples best describes the contents of your test.database file:&lt;BR /&gt;
&lt;BR /&gt;
(a) one character variable with the name Variables that has three records that have the values:&lt;BR /&gt;
A,&lt;BR /&gt;
B,&lt;BR /&gt;
C,&lt;BR /&gt;
&lt;BR /&gt;
(b) one character variable with the name Variables that has one record that has a value like:&lt;BR /&gt;
A, B, C,&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
(c) one character variable with the name Variables that has more than one record that has values like:&lt;BR /&gt;
A, B, C,&lt;BR /&gt;
D,&lt;BR /&gt;
E, F,&lt;BR /&gt;
&lt;BR /&gt;
or (d) something else and, if so, what?&lt;BR /&gt;
&lt;BR /&gt;
Art</description>
      <pubDate>Thu, 28 Apr 2011 19:56:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58182#M12625</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-04-28T19:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: Help with using macrovariables to filter observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58183#M12626</link>
      <description>(a)</description>
      <pubDate>Thu, 28 Apr 2011 20:06:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58183#M12626</guid>
      <dc:creator>Longduration</dc:creator>
      <dc:date>2011-04-28T20:06:36Z</dc:date>
    </item>
    <item>
      <title>Re: Help with using macrovariables to filter observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58184#M12627</link>
      <description>Longduration,&lt;BR /&gt;
&lt;BR /&gt;
I lied!  Not on purpose but, when I looked at my solution, I realized that what I need to know is what the file test.original looks like.&lt;BR /&gt;
&lt;BR /&gt;
I know it has a variable in it called Variables, but do the records in the file most closely approximate:&lt;BR /&gt;
&lt;BR /&gt;
(a) one value, e.g.:&lt;BR /&gt;
A&lt;BR /&gt;
B&lt;BR /&gt;
C&lt;BR /&gt;
&lt;BR /&gt;
(b) one or more values, e.g.:&lt;BR /&gt;
A B C&lt;BR /&gt;
D&lt;BR /&gt;
E F&lt;BR /&gt;
&lt;BR /&gt;
or (c) something else and, if so, what?&lt;BR /&gt;
&lt;BR /&gt;
Art</description>
      <pubDate>Thu, 28 Apr 2011 20:23:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58184#M12627</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-04-28T20:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: Help with using macrovariables to filter observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58185#M12628</link>
      <description>(a) again</description>
      <pubDate>Thu, 28 Apr 2011 21:30:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58185#M12628</guid>
      <dc:creator>Longduration</dc:creator>
      <dc:date>2011-04-28T21:30:08Z</dc:date>
    </item>
    <item>
      <title>Re: Help with using macrovariables to filter observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58186#M12629</link>
      <description>Then any of the suggestions would have worked.  My original, and the following, will work for either a or b.  My example uses b:&lt;BR /&gt;
[pre]&lt;BR /&gt;
libname test "c:\art";&lt;BR /&gt;
&lt;BR /&gt;
*create sample test.original file;&lt;BR /&gt;
data test.original;&lt;BR /&gt;
  informat variables $10.;&lt;BR /&gt;
  input variables &amp;amp;;&lt;BR /&gt;
  cards;&lt;BR /&gt;
A&lt;BR /&gt;
B C&lt;BR /&gt;
D&lt;BR /&gt;
E F G&lt;BR /&gt;
H&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data test.database;&lt;BR /&gt;
  input variables $;&lt;BR /&gt;
  cards;&lt;BR /&gt;
C,&lt;BR /&gt;
D,&lt;BR /&gt;
F,&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
* use a data step to write the necessary SAS code, using&lt;BR /&gt;
  the compress function to delete the unnecessary commas;&lt;BR /&gt;
filename name_chk temp;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  set test.database end=eof;&lt;BR /&gt;
  file name_chk;&lt;BR /&gt;
  variables=compress(variables,",");&lt;BR /&gt;
  if _n_ eq 1 then text =&lt;BR /&gt;
   cat("where variables contains ",quote(strip(VARIABLES)));&lt;BR /&gt;
  else text=&lt;BR /&gt;
   cat("or variables contains ",quote(strip(VARIABLES)));&lt;BR /&gt;
  put text;&lt;BR /&gt;
  if eof then put ";";&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
* select the desired records;&lt;BR /&gt;
data test.FILTERED;&lt;BR /&gt;
  set test.original;&lt;BR /&gt;
  %include name_chk / source2;;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Art</description>
      <pubDate>Thu, 28 Apr 2011 21:35:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58186#M12629</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-04-28T21:35:41Z</dc:date>
    </item>
    <item>
      <title>Re: Help with using macrovariables to filter observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58187#M12630</link>
      <description>How about this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data original;&lt;BR /&gt;
 input (Column1 Column2 TYPE Column4 ) ($);&lt;BR /&gt;
cards;&lt;BR /&gt;
x x A x&lt;BR /&gt;
x x G x&lt;BR /&gt;
x x B x&lt;BR /&gt;
x x D x&lt;BR /&gt;
x x C x&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
data database;&lt;BR /&gt;
 input variables $;&lt;BR /&gt;
cards;&lt;BR /&gt;
A,&lt;BR /&gt;
B,&lt;BR /&gt;
C,&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
 create table filtered as&lt;BR /&gt;
  select a.*&lt;BR /&gt;
   from original as a, database as b&lt;BR /&gt;
    where b.variables contains strip(a.type)&lt;BR /&gt;
    ;&lt;BR /&gt;
quit;  &lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Fri, 29 Apr 2011 02:18:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58187#M12630</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-04-29T02:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: Help with using macrovariables to filter observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58188#M12631</link>
      <description>Thank you all for your suggestions, its been very useful</description>
      <pubDate>Fri, 29 Apr 2011 11:44:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-using-macrovariables-to-filter-observations/m-p/58188#M12631</guid>
      <dc:creator>Longduration</dc:creator>
      <dc:date>2011-04-29T11:44:18Z</dc:date>
    </item>
  </channel>
</rss>

