<?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 to use compare function in a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-compare-function-in-a-macro/m-p/53739#M11347</link>
    <description>Hi Guys!&lt;BR /&gt;
My first post here. So please tell me if there are any rules/principles to follow while posting in this community.&lt;BR /&gt;
&lt;BR /&gt;
I want to compare a string (which comes from user) to a fixed string inside a macro.&lt;BR /&gt;
I wanted to use SAS function "compare" but it gives me error.&lt;BR /&gt;
&lt;BR /&gt;
Here is the relevant code and log&lt;BR /&gt;
&lt;BR /&gt;
&lt;U&gt;&lt;B&gt;code (from where user call the macro):&lt;/B&gt;&lt;/U&gt;&lt;BR /&gt;
&lt;BR /&gt;
%include "E:\Excel Conversion Project\variable analysis\VarAnalysis.sas";&lt;BR /&gt;
%let SpecialValues= -1, -2, -3, 1, 2 ,3, 9998, 9999, 9000, 9001, 9002, 9003, 8400, 8401, 8402, 8403, 9399, 9398, -599, -598, -597;&lt;BR /&gt;
&lt;BR /&gt;
ods csv file= "E:\Excel Conversion Project\variable analysis\GD_exampledata_vantage.csv";&lt;BR /&gt;
	%varAnalysis(data1.exampledata, BG90, 1, 10, 1, 1, vantage);&lt;BR /&gt;
ods csv close;&lt;BR /&gt;
&lt;BR /&gt;
&lt;U&gt;&lt;B&gt;code (macro):&lt;/B&gt;&lt;/U&gt;&lt;BR /&gt;
%macro varAnalysis(InputDataset, DependentVar, Weights, NumOfBuckets, IsNegative, RemoveSpecialValues, PredictorVar);	&lt;BR /&gt;
	&lt;BR /&gt;
	%if compare(&amp;amp;PredictorVar,allvars, 'i') = 0 %then	&lt;BR /&gt;
		%getGraphDataAllVar(&amp;amp;InputDataset, &amp;amp;DependentVar, &amp;amp;Weights, &amp;amp;NumOfBuckets, &amp;amp;IsNegative, &amp;amp;RemoveSpecialValues);	&lt;BR /&gt;
	%else&lt;BR /&gt;
		%getGraphData(&amp;amp;InputDataset, &amp;amp;DependentVar, &amp;amp;Weights, &amp;amp;NumOfBuckets, &amp;amp;IsNegative, &amp;amp;RemoveSpecialValues, &amp;amp;PredictorVar);&lt;BR /&gt;
&lt;BR /&gt;
%mend varAnalysis;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;&lt;BR /&gt;
&lt;U&gt;log:&lt;/U&gt;&lt;/B&gt;&lt;BR /&gt;
505    %include "E:\Excel Conversion Project\variable analysis\VarAnalysis.sas";&lt;BR /&gt;
NOTE: Libref DATA1 was successfully assigned as follows:&lt;BR /&gt;
      Engine:        V9&lt;BR /&gt;
      Physical Name: E:\Excel Conversion Project\testing&lt;BR /&gt;
NOTE: Libref DATA2 was successfully assigned as follows:&lt;BR /&gt;
      Engine:        V9&lt;BR /&gt;
      Physical Name: E:\Excel Conversion Project\testing\temp(to be deleted)&lt;BR /&gt;
NOTE: Libref DATA3 was successfully assigned as follows:&lt;BR /&gt;
      Engine:        V9&lt;BR /&gt;
      Physical Name: E:\Excel Conversion Project&lt;BR /&gt;
748&lt;BR /&gt;
749    %let SpecialValues= -1, -2, -3, 1, 2 ,3, 9998, 9999, 9000, 9001, 9002, 9003, 8400, 8401, 8402,&lt;BR /&gt;
749  ! 8403, 9399, 9398, -599, -598, -597;&lt;BR /&gt;
750&lt;BR /&gt;
751    ods csv file= "E:\Excel Conversion Project\variable analysis\GD_exampledata_vantage.csv";&lt;BR /&gt;
NOTE: Writing CSV Body file: E:\Excel Conversion Project\variable analysis\GD_exampledata_vantage.csv&lt;BR /&gt;
752&lt;BR /&gt;
753    %varAnalysis(data1.exampledata, BG90, 1, 10, 1, 1, vantage);&lt;BR /&gt;
MLOGIC(VARANALYSIS):  Beginning execution.&lt;BR /&gt;
MLOGIC(VARANALYSIS):  Parameter INPUTDATASET has value data1.exampledata&lt;BR /&gt;
MLOGIC(VARANALYSIS):  Parameter DEPENDENTVAR has value BG90&lt;BR /&gt;
MLOGIC(VARANALYSIS):  Parameter WEIGHTS has value 1&lt;BR /&gt;
MLOGIC(VARANALYSIS):  Parameter NUMOFBUCKETS has value 10&lt;BR /&gt;
MLOGIC(VARANALYSIS):  Parameter ISNEGATIVE has value 1&lt;BR /&gt;
MLOGIC(VARANALYSIS):  Parameter REMOVESPECIALVALUES has value 1&lt;BR /&gt;
MLOGIC(VARANALYSIS):  Parameter PREDICTORVAR has value vantage&lt;BR /&gt;
SYMBOLGEN:  Macro variable PREDICTORVAR resolves to vantage&lt;BR /&gt;
&lt;B&gt;ERROR: Required operator not found in expression: compare(&amp;amp;PredictorVar,allvars, 'i') = 0&lt;/B&gt;&lt;BR /&gt;
ERROR: The macro VARANALYSIS will stop executing.&lt;BR /&gt;
MLOGIC(VARANALYSIS):  Ending execution.&lt;BR /&gt;
754&lt;BR /&gt;
755    ods csv close;&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
PS:  In case I use   %if &amp;amp;PredictorVar = allvars %then&lt;BR /&gt;
 the code runs fine. I wanted to use compare function to ignore case, extra spaces etc.

Message was edited by: grvs</description>
    <pubDate>Tue, 14 Oct 2008 13:25:59 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-10-14T13:25:59Z</dc:date>
    <item>
      <title>how to use compare function in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-compare-function-in-a-macro/m-p/53739#M11347</link>
      <description>Hi Guys!&lt;BR /&gt;
My first post here. So please tell me if there are any rules/principles to follow while posting in this community.&lt;BR /&gt;
&lt;BR /&gt;
I want to compare a string (which comes from user) to a fixed string inside a macro.&lt;BR /&gt;
I wanted to use SAS function "compare" but it gives me error.&lt;BR /&gt;
&lt;BR /&gt;
Here is the relevant code and log&lt;BR /&gt;
&lt;BR /&gt;
&lt;U&gt;&lt;B&gt;code (from where user call the macro):&lt;/B&gt;&lt;/U&gt;&lt;BR /&gt;
&lt;BR /&gt;
%include "E:\Excel Conversion Project\variable analysis\VarAnalysis.sas";&lt;BR /&gt;
%let SpecialValues= -1, -2, -3, 1, 2 ,3, 9998, 9999, 9000, 9001, 9002, 9003, 8400, 8401, 8402, 8403, 9399, 9398, -599, -598, -597;&lt;BR /&gt;
&lt;BR /&gt;
ods csv file= "E:\Excel Conversion Project\variable analysis\GD_exampledata_vantage.csv";&lt;BR /&gt;
	%varAnalysis(data1.exampledata, BG90, 1, 10, 1, 1, vantage);&lt;BR /&gt;
ods csv close;&lt;BR /&gt;
&lt;BR /&gt;
&lt;U&gt;&lt;B&gt;code (macro):&lt;/B&gt;&lt;/U&gt;&lt;BR /&gt;
%macro varAnalysis(InputDataset, DependentVar, Weights, NumOfBuckets, IsNegative, RemoveSpecialValues, PredictorVar);	&lt;BR /&gt;
	&lt;BR /&gt;
	%if compare(&amp;amp;PredictorVar,allvars, 'i') = 0 %then	&lt;BR /&gt;
		%getGraphDataAllVar(&amp;amp;InputDataset, &amp;amp;DependentVar, &amp;amp;Weights, &amp;amp;NumOfBuckets, &amp;amp;IsNegative, &amp;amp;RemoveSpecialValues);	&lt;BR /&gt;
	%else&lt;BR /&gt;
		%getGraphData(&amp;amp;InputDataset, &amp;amp;DependentVar, &amp;amp;Weights, &amp;amp;NumOfBuckets, &amp;amp;IsNegative, &amp;amp;RemoveSpecialValues, &amp;amp;PredictorVar);&lt;BR /&gt;
&lt;BR /&gt;
%mend varAnalysis;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;&lt;BR /&gt;
&lt;U&gt;log:&lt;/U&gt;&lt;/B&gt;&lt;BR /&gt;
505    %include "E:\Excel Conversion Project\variable analysis\VarAnalysis.sas";&lt;BR /&gt;
NOTE: Libref DATA1 was successfully assigned as follows:&lt;BR /&gt;
      Engine:        V9&lt;BR /&gt;
      Physical Name: E:\Excel Conversion Project\testing&lt;BR /&gt;
NOTE: Libref DATA2 was successfully assigned as follows:&lt;BR /&gt;
      Engine:        V9&lt;BR /&gt;
      Physical Name: E:\Excel Conversion Project\testing\temp(to be deleted)&lt;BR /&gt;
NOTE: Libref DATA3 was successfully assigned as follows:&lt;BR /&gt;
      Engine:        V9&lt;BR /&gt;
      Physical Name: E:\Excel Conversion Project&lt;BR /&gt;
748&lt;BR /&gt;
749    %let SpecialValues= -1, -2, -3, 1, 2 ,3, 9998, 9999, 9000, 9001, 9002, 9003, 8400, 8401, 8402,&lt;BR /&gt;
749  ! 8403, 9399, 9398, -599, -598, -597;&lt;BR /&gt;
750&lt;BR /&gt;
751    ods csv file= "E:\Excel Conversion Project\variable analysis\GD_exampledata_vantage.csv";&lt;BR /&gt;
NOTE: Writing CSV Body file: E:\Excel Conversion Project\variable analysis\GD_exampledata_vantage.csv&lt;BR /&gt;
752&lt;BR /&gt;
753    %varAnalysis(data1.exampledata, BG90, 1, 10, 1, 1, vantage);&lt;BR /&gt;
MLOGIC(VARANALYSIS):  Beginning execution.&lt;BR /&gt;
MLOGIC(VARANALYSIS):  Parameter INPUTDATASET has value data1.exampledata&lt;BR /&gt;
MLOGIC(VARANALYSIS):  Parameter DEPENDENTVAR has value BG90&lt;BR /&gt;
MLOGIC(VARANALYSIS):  Parameter WEIGHTS has value 1&lt;BR /&gt;
MLOGIC(VARANALYSIS):  Parameter NUMOFBUCKETS has value 10&lt;BR /&gt;
MLOGIC(VARANALYSIS):  Parameter ISNEGATIVE has value 1&lt;BR /&gt;
MLOGIC(VARANALYSIS):  Parameter REMOVESPECIALVALUES has value 1&lt;BR /&gt;
MLOGIC(VARANALYSIS):  Parameter PREDICTORVAR has value vantage&lt;BR /&gt;
SYMBOLGEN:  Macro variable PREDICTORVAR resolves to vantage&lt;BR /&gt;
&lt;B&gt;ERROR: Required operator not found in expression: compare(&amp;amp;PredictorVar,allvars, 'i') = 0&lt;/B&gt;&lt;BR /&gt;
ERROR: The macro VARANALYSIS will stop executing.&lt;BR /&gt;
MLOGIC(VARANALYSIS):  Ending execution.&lt;BR /&gt;
754&lt;BR /&gt;
755    ods csv close;&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
PS:  In case I use   %if &amp;amp;PredictorVar = allvars %then&lt;BR /&gt;
 the code runs fine. I wanted to use compare function to ignore case, extra spaces etc.

Message was edited by: grvs</description>
      <pubDate>Tue, 14 Oct 2008 13:25:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-compare-function-in-a-macro/m-p/53739#M11347</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-14T13:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: how to use compare function in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-compare-function-in-a-macro/m-p/53740#M11348</link>
      <description>%sysfunc(compare(&amp;amp;PredictorVar,&amp;amp;allvars,i))</description>
      <pubDate>Tue, 14 Oct 2008 14:27:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-compare-function-in-a-macro/m-p/53740#M11348</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2008-10-14T14:27:50Z</dc:date>
    </item>
  </channel>
</rss>

