BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
GKati
Pyrite | Level 9

Dear SAS users,

 

I am running the following code:

%macro do_all;
%do i=0 %to 1 %by 0.25;
options mprint symbolgen;

Data c_&i;
set individuals;
contractbypc=&i;
keep klantnummer treated year contractbypc;
run;

%end;
%mend do_all;
%do_all;

 I am getting the following error msg:

 

 

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:

.25

ERROR: The %BY value of the %DO I loop is invalid.

ERROR: The macro DO_ALL will stop executing.

 

I know its the %by part of the statement than is wrong, but I don't know how to fix it.

 

Thanks for your help.

 

K.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

You can't use fractional or decimal arithmetic in a macro %DO statement. You can only use integers. Here is a solution to use non-integer values in a %DO statement: http://documentation.sas.com/?docsetId=mcrolref&docsetTarget=p02f7difkhfytsn1dzhaas0rdf4n.htm&docset...

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

You can't use fractional or decimal arithmetic in a macro %DO statement. You can only use integers. Here is a solution to use non-integer values in a %DO statement: http://documentation.sas.com/?docsetId=mcrolref&docsetTarget=p02f7difkhfytsn1dzhaas0rdf4n.htm&docset...

--
Paige Miller
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You can't call a dataset c_0.25 for example either.  Why do you want to split similar data out in the first place, it just makes any further code much harder to write and takes more disk space?

I suppose you could do:

data _null_;
  do i=0 to 1 by 0.25;
    call execute(cats('data c_',tranwrd(put(i,best.),".","_"),'; set individuals; where contractbypc=',put(i,best.),'; run;'));
  end;
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1596 views
  • 0 likes
  • 3 in conversation