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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.