BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi Guys!
My first post here. So please tell me if there are any rules/principles to follow while posting in this community.

I want to compare a string (which comes from user) to a fixed string inside a macro.
I wanted to use SAS function "compare" but it gives me error.

Here is the relevant code and log

code (from where user call the macro):

%include "E:\Excel Conversion Project\variable analysis\VarAnalysis.sas";
%let SpecialValues= -1, -2, -3, 1, 2 ,3, 9998, 9999, 9000, 9001, 9002, 9003, 8400, 8401, 8402, 8403, 9399, 9398, -599, -598, -597;

ods csv file= "E:\Excel Conversion Project\variable analysis\GD_exampledata_vantage.csv";
%varAnalysis(data1.exampledata, BG90, 1, 10, 1, 1, vantage);
ods csv close;

code (macro):
%macro varAnalysis(InputDataset, DependentVar, Weights, NumOfBuckets, IsNegative, RemoveSpecialValues, PredictorVar);

%if compare(&PredictorVar,allvars, 'i') = 0 %then
%getGraphDataAllVar(&InputDataset, &DependentVar, &Weights, &NumOfBuckets, &IsNegative, &RemoveSpecialValues);
%else
%getGraphData(&InputDataset, &DependentVar, &Weights, &NumOfBuckets, &IsNegative, &RemoveSpecialValues, &PredictorVar);

%mend varAnalysis;



log:

505 %include "E:\Excel Conversion Project\variable analysis\VarAnalysis.sas";
NOTE: Libref DATA1 was successfully assigned as follows:
Engine: V9
Physical Name: E:\Excel Conversion Project\testing
NOTE: Libref DATA2 was successfully assigned as follows:
Engine: V9
Physical Name: E:\Excel Conversion Project\testing\temp(to be deleted)
NOTE: Libref DATA3 was successfully assigned as follows:
Engine: V9
Physical Name: E:\Excel Conversion Project
748
749 %let SpecialValues= -1, -2, -3, 1, 2 ,3, 9998, 9999, 9000, 9001, 9002, 9003, 8400, 8401, 8402,
749 ! 8403, 9399, 9398, -599, -598, -597;
750
751 ods csv file= "E:\Excel Conversion Project\variable analysis\GD_exampledata_vantage.csv";
NOTE: Writing CSV Body file: E:\Excel Conversion Project\variable analysis\GD_exampledata_vantage.csv
752
753 %varAnalysis(data1.exampledata, BG90, 1, 10, 1, 1, vantage);
MLOGIC(VARANALYSIS): Beginning execution.
MLOGIC(VARANALYSIS): Parameter INPUTDATASET has value data1.exampledata
MLOGIC(VARANALYSIS): Parameter DEPENDENTVAR has value BG90
MLOGIC(VARANALYSIS): Parameter WEIGHTS has value 1
MLOGIC(VARANALYSIS): Parameter NUMOFBUCKETS has value 10
MLOGIC(VARANALYSIS): Parameter ISNEGATIVE has value 1
MLOGIC(VARANALYSIS): Parameter REMOVESPECIALVALUES has value 1
MLOGIC(VARANALYSIS): Parameter PREDICTORVAR has value vantage
SYMBOLGEN: Macro variable PREDICTORVAR resolves to vantage
ERROR: Required operator not found in expression: compare(&PredictorVar,allvars, 'i') = 0
ERROR: The macro VARANALYSIS will stop executing.
MLOGIC(VARANALYSIS): Ending execution.
754
755 ods csv close;



PS: In case I use %if &PredictorVar = allvars %then
the code runs fine. I wanted to use compare function to ignore case, extra spaces etc. Message was edited by: grvs
1 REPLY 1
data_null__
Jade | Level 19
%sysfunc(compare(&PredictorVar,&allvars,i))

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 848 views
  • 0 likes
  • 2 in conversation