Hi,
%let ab= \\trg\mt-4tsr\stud\err\pgm\out
%macro tr(ds=);
%if &ds. = &ab %then %do;
data afg;
set sashelp.cars;
run;
%mend;
%tr(ds=&ab);
i am getting error
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
operand is required. The condition was: &ds.=&ab.
Hi @sam1231
1) there is semicolon missing in the %let statement
2) there is %end; missing in the macro code
3) make it:
%bquote(&ds.) = %bquote(&ab)
4) read this article: https://stats.idre.ucla.edu/wp-content/uploads/2016/02/bt185.pdf
5) and this article: https://support.sas.com/resources/papers/proceedings09/022-2009.pdf
All the best
Bart
Adding to @yabwon 's recommendations for macro quoting papers:
https://support.sas.com/resources/papers/proceedings/proceedings/sugi28/011-28.pdf
https://analytics.ncsu.edu/sesug/2008/CS-049.pdf
All four are excellent papers, worth reading at least once a year. : )
You might want to try this
%if %bquote(&ds) = %bquote(&ab) %then %do;
If that's not it, please turn on the debugging options as follows:
options mprint mlogic symbolgen;
run the code again, and show us the entire LOG file (not just the error messages) by clicking on the {i} icon and pasting the log into the window that appears. Do not skip this step.
%BQUOTE should solve this. Another easy way:
%if "&ds." = "&ab" %then %do;
The basic problem is that macro language sees the "-" in the middle of the string and decides that it needs to subtract.
The use of double quotes suppresses that interpretation of the "-" although it introduces complications if one or both strings contain leading or trailing blanks.
Fix the obvious ERRORs (missing semicolon and %end), and use quotes for the strings:
73 %let ab= \\trg\mt-4tsr\stud\err\pgm\out; 74 75 %macro tr(ds=); 76 %if "&ds." = "&ab" %then %do; 77 data afg; 78 set sashelp.cars; 79 run; 80 %end; 81 %mend; 82 83 %tr(ds=&ab); NOTE: There were 428 observations read from the data set SASHELP.CARS. NOTE: The data set WORK.AFG has 428 observations and 15 variables.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.