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

Hi...I am trying to do a loop from one date to another but I am getting the following error message 22-322...any suggestions how to correct this...Thanks.

 

269 DATA K;

270 do date=&FROMYEAR7 to &TOYEAR7;

NOTE: Line generated by the macro variable "FROMYEAR7".

270 01JAN1900

_______

22

NOTE: Line generated by the macro variable "TOYEAR7".

270 31DEC2100

_______

22

ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, ',', -,

/, <, <=, <>, =, >, ><, >=, AND, BY, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE,

NG, NL, NOTIN, OR, ^=, |, ||, ~=.

271 if date= &FROMYEAR7 then do;

NOTE: Line generated by the macro variable "FROMYEAR7".

271 01JAN1900

_______

388

76

ERROR 388-185: Expecting an arithmetic operator.

ERROR 76-322: Syntax error, statement will be ignored.

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Since your macro variables resolve to SAS dates you need to reference them as date strings like so (assuming the date variable is in fact a SAS date):

 

do date="&FROMYEAR7"d to "&TOYEAR7"d;

 

View solution in original post

4 REPLIES 4
DartRodrigo
Lapis Lazuli | Level 10

Hi mate, 

 

It is possible that you missed out some operator during your do loop. Checkout the syntax and paste the code here if possible

 

tks

SASKiwi
PROC Star

Since your macro variables resolve to SAS dates you need to reference them as date strings like so (assuming the date variable is in fact a SAS date):

 

do date="&FROMYEAR7"d to "&TOYEAR7"d;

 

twildone
Pyrite | Level 9
Hi...thanks....the double quotation marks rather than the single quotation marks resolved the problem and worked perfectly.
Cynthia_sas
Diamond | Level 26
Hi:
Without seeing more of your code, it looks to me like you need to specify date constants in your do loop:
do date="&FROMYEAR7"d to "&TOYEAR7"d;

Please review this example: http://support.sas.com/kb/24/573.html

When you are using Macro variables as the start and end variables, you need to enclose your macro variable values in double quotes (instead of single quotes), but the trailing D to indicate a date value is required. Otherwise, you get an error because this:

do date=01JAN1900 to 31DEC2100;

is not valid in code, but this would be:

data testit;
do date="01JAN1900"d to "31DEC2100"d;
put 'internal= ' date '~~~' 'formatted= ' date date9.;
end;
run;

cynthia

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 4 replies
  • 3886 views
  • 4 likes
  • 4 in conversation