<?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: If then Scan Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390721#M93759</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You cannot use &lt;STRONG&gt;%if&lt;/STRONG&gt; &amp;lt;cond1&amp;gt; &lt;STRONG&gt;or/and&lt;/STRONG&gt; &amp;lt;cond2&amp;gt;.&lt;/P&gt;
&lt;P&gt;And you don't need &amp;nbsp;&lt;STRONG&gt;%if&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro xyz(dname=);
data t;
     Length X $15;
     if scan("&amp;amp;dname.",-1,'_') ne 'scores.tsv' and
        scan("&amp;amp;dname.",-1,'_') ne 'income.tsv'  
     then x='Finance Data';
    else X='Scores,Income';
run;
%mend xyz;

%xyz(dname=dataset_scores.tsv);
%xyz(dname=dataset_income.tsv);
%xyz(dname=dataset.tsv);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt; to do what you want. See next coed:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 24 Aug 2017 18:28:03 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2017-08-24T18:28:03Z</dc:date>
    <item>
      <title>If then Scan Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390710#M93753</link>
      <description>&lt;P&gt;TIn the below macro, I expect to see the variable X to be "Finance Data" if the dname takes dataset.tsv as parameter and&amp;nbsp;&lt;/P&gt;&lt;P&gt;X will be "Scores,Income" when dname takes dataset_scores.tsv or dataset_income.tsv.&lt;/P&gt;&lt;P&gt;But I see only "Finance Data" as the value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro xyz(dname=);&lt;BR /&gt;data t;&lt;BR /&gt;Length X $15;&lt;BR /&gt;%if (%scan(&amp;amp;dname.,-1,'_') ne 'scores.tsv' or %scan(&amp;amp;dname.,-1,'_') ne 'income.tsv') %then %do;&lt;BR /&gt;x='Finance Data';&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;X='Scores,Income';&lt;BR /&gt;%end;&lt;BR /&gt;run;&lt;BR /&gt;%mend xyz;&lt;BR /&gt;%xyz(dname=dataset_scores.tsv);&lt;BR /&gt;%xyz(dname=dataset_income.tsv);&lt;BR /&gt;%xyz(dname=dataset.tsv);&lt;/P&gt;</description>
      <pubDate>Thu, 24 Aug 2017 18:07:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390710#M93753</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2017-08-24T18:07:48Z</dc:date>
    </item>
    <item>
      <title>Re: If then Scan Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390713#M93754</link>
      <description>&lt;P&gt;Try removing quotes like -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%macro xyz(dname=);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;data t;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Length X $15;&lt;/SPAN&gt;&lt;BR /&gt;&lt;STRONG&gt;%if (%scan(&amp;amp;dname.,-1,'_') ne scores.tsv or %scan(&amp;amp;dname.,-1,'_') ne income.tsv) %then %do;&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;x='Finance Data';&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;%end;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;%else %do;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;X='Scores,Income';&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;%end;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;%mend xyz;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;%xyz(dname=dataset_scores.tsv);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;%xyz(dname=dataset_income.tsv);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;%xyz(dname=dataset.tsv);&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Aug 2017 18:19:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390713#M93754</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-08-24T18:19:39Z</dc:date>
    </item>
    <item>
      <title>Re: If then Scan Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390714#M93755</link>
      <description>&lt;P&gt;Basic logic problem with "OR" (besides apparently mixing data step and macro code).&lt;/P&gt;
&lt;P&gt;If x ne 1 or x ne 2 is ALWAYS true. When x=1 the "ne 2" part is true so you get that selected, if x=2 the first part is true. If either part of an or is true the result is true.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is this what you were looking for:&lt;/P&gt;
&lt;PRE&gt;%macro xyz(dname=);
data t;
   Length X $15;
   if scan("&amp;amp;dname.",-1,'_') In ( 'scores.tsv' 'income.tsv') then do;
      X='Scores,Income';
   end;
   else do;
      x='Finance Data';
   end;
run;
%mend xyz;
%xyz(dname=dataset_scores.tsv);
%xyz(dname=dataset_income.tsv);
%xyz(dname=dataset.tsv);&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Aug 2017 18:21:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390714#M93755</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-08-24T18:21:51Z</dc:date>
    </item>
    <item>
      <title>Re: If then Scan Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390716#M93756</link>
      <description>&lt;P&gt;No, It did not work either&lt;/P&gt;</description>
      <pubDate>Thu, 24 Aug 2017 18:22:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390716#M93756</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2017-08-24T18:22:59Z</dc:date>
    </item>
    <item>
      <title>Re: If then Scan Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390720#M93758</link>
      <description>&lt;P&gt;Please paste the log. Run with options mlogic and mprint and paste the log here. Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 24 Aug 2017 18:25:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390720#M93758</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-08-24T18:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: If then Scan Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390721#M93759</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You cannot use &lt;STRONG&gt;%if&lt;/STRONG&gt; &amp;lt;cond1&amp;gt; &lt;STRONG&gt;or/and&lt;/STRONG&gt; &amp;lt;cond2&amp;gt;.&lt;/P&gt;
&lt;P&gt;And you don't need &amp;nbsp;&lt;STRONG&gt;%if&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro xyz(dname=);
data t;
     Length X $15;
     if scan("&amp;amp;dname.",-1,'_') ne 'scores.tsv' and
        scan("&amp;amp;dname.",-1,'_') ne 'income.tsv'  
     then x='Finance Data';
    else X='Scores,Income';
run;
%mend xyz;

%xyz(dname=dataset_scores.tsv);
%xyz(dname=dataset_income.tsv);
%xyz(dname=dataset.tsv);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt; to do what you want. See next coed:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Aug 2017 18:28:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390721#M93759</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-08-24T18:28:03Z</dc:date>
    </item>
    <item>
      <title>Re: If then Scan Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390722#M93760</link>
      <description>&lt;P&gt;a comma(,) is not required&amp;nbsp;between values?&lt;/P&gt;&lt;PRE&gt; 'scores.tsv' 'income.tsv')&lt;BR /&gt;?&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Aug 2017 18:28:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390722#M93760</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2017-08-24T18:28:34Z</dc:date>
    </item>
    <item>
      <title>Re: If then Scan Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390724#M93762</link>
      <description>&lt;P&gt;btw you need an AND operator rather than OR:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%if (%scan(&amp;amp;dname.,-1,'_') ne scores.tsv and %scan(&amp;amp;dname.,-1,'_') ne income.tsv) %then %do;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Aug 2017 18:30:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390724#M93762</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-08-24T18:30:24Z</dc:date>
    </item>
    <item>
      <title>Re: If then Scan Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390728#M93766</link>
      <description>No, the comma is optional.</description>
      <pubDate>Thu, 24 Aug 2017 19:05:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390728#M93766</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2017-08-24T19:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: If then Scan Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390731#M93768</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;what do you mean by "You cannot use &lt;STRONG&gt;%if&lt;/STRONG&gt; &amp;lt;cond1&amp;gt; &lt;STRONG&gt;or/and&lt;/STRONG&gt; &amp;lt;cond2&amp;gt;"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro language understands the operators OR and AND, e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;21   %macro ck(cond1,cond2);
22     %put &amp;amp;=cond1 &amp;amp;=cond2;
23     %if &amp;amp;cond1 and &amp;amp;cond2 %then %put %nrstr(&amp;amp;cond1 and &amp;amp;cond2) is True;
24     %else %put %nrstr(&amp;amp;cond1 and &amp;amp;cond2) is False;
25
26     %if &amp;amp;cond1 or &amp;amp;cond2 %then %put %nrstr(&amp;amp;cond1 or &amp;amp;cond2) is True;
27     %else %put %nrstr(&amp;amp;cond1 or &amp;amp;cond2) is False;
28   %mend ck;
29
30   %ck(0,1)
COND1=0 COND2=1
&amp;amp;cond1 and &amp;amp;cond2 is False
&amp;amp;cond1 or &amp;amp;cond2 is True
31   %ck(1,1)
COND1=1 COND2=1
&amp;amp;cond1 and &amp;amp;cond2 is True
&amp;amp;cond1 or &amp;amp;cond2 is True
32   %ck(0,0)
COND1=0 COND2=0
&amp;amp;cond1 and &amp;amp;cond2 is False
&amp;amp;cond1 or &amp;amp;cond2 is False
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Aug 2017 19:13:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390731#M93768</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2017-08-24T19:13:17Z</dc:date>
    </item>
    <item>
      <title>Re: If then Scan Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390733#M93769</link>
      <description>&lt;P&gt;Extendng the logic to drop variables from dataset have.&lt;/P&gt;&lt;P&gt;&amp;nbsp;This fails.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrobound"&gt;%macro&lt;/SPAN&gt; xyz&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;dname&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; %scan(&amp;amp;dname.,-2,'.');&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
     &lt;SPAN class="token function"&gt;Length&lt;/SPAN&gt; X &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;15&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;    set have;
     &lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;scan&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"&amp;amp;dname."&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;-1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'_'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;ne&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;'scores.tsv'&lt;/SPAN&gt; and
        &lt;SPAN class="token function"&gt;scan&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"&amp;amp;dname."&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;-1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'_'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;ne&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;'income.tsv'&lt;/SPAN&gt;  
     &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; do;&lt;BR /&gt;        x&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'Finance Data'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;drop var1;
    &lt;SPAN class="token keyword"&gt;else&lt;/SPAN&gt; do;&lt;BR /&gt;   X&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'Scores,Income'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;   drop var1 var2;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token macrobound"&gt;%mend&lt;/SPAN&gt; xyz&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

&lt;SPAN class="token macroname"&gt;%xyz&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;dname&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;dataset_scores&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;tsv&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token macroname"&gt;%xyz&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;dname&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;dataset_income&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;tsv&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token macroname"&gt;%xyz&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;dname&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;dataset&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;tsv&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Aug 2017 19:30:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390733#M93769</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2017-08-24T19:30:05Z</dc:date>
    </item>
    <item>
      <title>Re: If then Scan Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390736#M93771</link>
      <description>&lt;P&gt;I'm afraid drop is a compile time statement and not an executable statement. Therefore you cannot conditionally execute a drop statement. You would have to choose your original idea of the macro where you can generate a drop statement based on &amp;nbsp;macro if condition.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Aug 2017 19:35:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390736#M93771</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-08-24T19:35:25Z</dc:date>
    </item>
    <item>
      <title>Re: If then Scan Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390739#M93773</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;, I'm probably locked on a very old sas version when -&lt;STRONG&gt; %if&lt;/STRONG&gt; &amp;lt;cond1&amp;gt; &lt;STRONG&gt;or/and&lt;/STRONG&gt; &amp;lt;cond2&amp;gt; - did not work.&lt;BR /&gt;Thank you for yor remark.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Aug 2017 19:55:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390739#M93773</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-08-24T19:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: If then Scan Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390742#M93774</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16600"&gt;@SASPhile&lt;/a&gt;&amp;nbsp;- your code fail at those two lines:&lt;/P&gt;
&lt;PRE&gt;    then do;        x='Finance Data';drop var1;
    else do;   X='Scores,Income';   drop var1 var2;&lt;/PRE&gt;
&lt;P&gt;1) you miss END to close DO staement.&lt;/P&gt;
&lt;P&gt;2) DROP staement cannot be conditional in a data step, it has to be done with macro code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro xyz(dname=);
data t;
     Length X $15;
     if scan("&amp;amp;dname.",-1,'_') ne 'scores.tsv' and
        scan("&amp;amp;dname.",-1,'_') ne 'income.tsv'  
     then x='Finance Data';
     else X='Scores,Income';
     
  %if %scan(&amp;amp;dname, -1, _ ) = %str(Finance Data)
   %then %do; Drop var1; %end;
   %else %do; Drop var1 var2; %end; 

run;
%mend xyz;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Aug 2017 20:06:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-Scan-Macro/m-p/390742#M93774</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-08-24T20:06:57Z</dc:date>
    </item>
  </channel>
</rss>

