BookmarkSubscribeRSS Feed
sam1231
Obsidian | Level 7

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.

 

 

5 REPLIES 5
yabwon
Amethyst | Level 16

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

 

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Quentin
Super User

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. : )

 

The Boston Area SAS Users Group is hosting free webinars!

Register now at https://www.basug.org/events.
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Astounding
PROC Star

%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.

Kurt_Bremser
Super User

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.

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand in the Innovate Hub.

Watch 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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1948 views
  • 2 likes
  • 6 in conversation