BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
klindsey
Fluorite | Level 6

Hello,

I have been trying to modify my code so that I can get a row with all of the same information on each date between two dates. I have tried to research this myself, but I keep getting the error: 

ERROR: Invalid DO loop control information, either the INITIAL or TO expression is missing or the BY expression is missing, zero,
or invalid.
 
My code currently is:
data have;
set want;
do offset=0 to intck('day', firstday, finalday);
date= intnx('day',firstday,offset);
output;
end;
format date date9.;
drop firstday finalday;
run;
 
Thank you for your help!
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

The error is saying that one of your two variables is missing.  So you need to fix that.

 

There is no need to use INTNX() and INTCK() when the interval you are moving by is the unit that the values are already stored in. DATE values are stored in DAYS. DATETIME and TIME values are stored in SECONDS.

 

data have;
   set want;
   if missing(firstday) or missing(finalday) then put 'ERROR: missing dates' firstday= finalday= ;
   else do date= firstday to finalday;
     output;
   end;
   format date date9.;
   drop firstday finalday;
run;

 

 

View solution in original post

4 REPLIES 4
Reeza
Super User
data have;
set want;
do date=firstday to finalday;
output;
end;
format date date9.;
drop firstday finalday;
run;
 
klindsey
Fluorite | Level 6

This was the first code I used, and I still get the same error.

Tom
Super User Tom
Super User

The error is saying that one of your two variables is missing.  So you need to fix that.

 

There is no need to use INTNX() and INTCK() when the interval you are moving by is the unit that the values are already stored in. DATE values are stored in DAYS. DATETIME and TIME values are stored in SECONDS.

 

data have;
   set want;
   if missing(firstday) or missing(finalday) then put 'ERROR: missing dates' firstday= finalday= ;
   else do date= firstday to finalday;
     output;
   end;
   format date date9.;
   drop firstday finalday;
run;

 

 

klindsey
Fluorite | Level 6
Ah! It looks like this was it! It just wasn't working since I had missing values. Thank you!

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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