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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2 replies
  • 1213 views
  • 0 likes
  • 3 in conversation