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

Hello, I have found a solution to code concomitant medication use in SAS, but my code runs with error. Any suggestions on how to proceed?

 

ERROR: Invalid DO loop control information, either the INITIAL or TO expression is missing or the BY expression is missing, zero, or invalid.

 

data have;
input ID	DRUG $	START_DT :mmddyy.	DAYS_SUPP	END_DT :mmddyy.;
datalines;;
1	A	2/17/10	30	3/19/10
1	B	5/6/09	30	6/5/09
1	C	7/9/11	60	9/7/11
1	E	3/1/10	90	5/30/10
1	B	1/1/09	90	4/1/09
1	D	2/1/09	30	3/3/09
1	C	5/6/12	90	8/4/12
2	B	4/1/12	60	5/31/12
2	A	7/1/10	30	7/31/10
2	C	8/3/10	90	11/1/10
2	D	11/1/13	90	1/30/14
2	E	12/5/13	90	3/5/14
2	A	2/1/11	90	5/2/11
2   F   12/16/13 30 1/14/14
;

data days;
set have;
dum = 1;
do day = start_dt to end_dt;
by id; output; end; format day yymmdd10.; keep id drug day; run; proc sort data=days; by id day drug; run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

The error message is very clear. You have missing values. The LOG should show you the missing values.

Example:

19    data have;
20      input ID  DRUG $  START_DT :mmddyy. DAYS_SUPP END_DT :mmddyy.;
21      format start_dt end_dt yymmdd10.;
22    datalines;

NOTE: Invalid data for START_DT in line 24 5-11.
RULE:       ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
24          1 B 5/60/09 30  6/5/09
ID=1 DRUG=B START_DT=. DAYS_SUPP=30 END_DT=2009-06-05 _ERROR_=1 _N_=2
NOTE: The data set WORK.HAVE has 2 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


22  !           ;
25    ;
26
27    data days;
28      set have;
29      dum = 1;
30      do day = start_dt to end_dt;
31        output;
32      end;
33      format day yymmdd10.;
34    run;

ERROR: Invalid DO loop control information, either the INITIAL or TO expression is missing or the BY expression is missing, zero, or
       invalid.
ID=1 DRUG=B START_DT=. DAYS_SUPP=30 END_DT=2009-06-05 dum=1 day=. _ERROR_=1 _N_=2

You can trap those cases and not execute the DO loop when there are missing values.

if n(start_dt,end_dt)=2 then do day = start_dt to end_dt;

View solution in original post

7 REPLIES 7
sbxkoenk
SAS Super FREQ

Your code does NOT throw an ERROR.

Koen

PaigeMiller
Diamond | Level 26

Whenever you get an error in the log, show us the ENTIRE log for the data step with the error, that's every single line in the log for the data step with the error, with nothing chopped out. Please follow these instructions to provide the log:

 

Please copy the log as text and paste it into the window that appears when you click on the </> icon. DO NOT SKIP THE PART IN RED.

--
Paige Miller
ballardw
Super User

Just for giggles, what do you think the BY ID in the Data Days data step is contributing to your code?

ChrisNZ
Tourmaline | Level 20

@ballardw The BY ID will do 2 things: 1) slow down the code 2) verify that the data is sorted (but this information is not saved).

macro_2349
Calcite | Level 5
@ballardw @ChrisNZ
You are correct. This is redundant given that the next step in my program is a PROC sort. Thank for making this much more efficient for me!
Tom
Super User Tom
Super User

The error message is very clear. You have missing values. The LOG should show you the missing values.

Example:

19    data have;
20      input ID  DRUG $  START_DT :mmddyy. DAYS_SUPP END_DT :mmddyy.;
21      format start_dt end_dt yymmdd10.;
22    datalines;

NOTE: Invalid data for START_DT in line 24 5-11.
RULE:       ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
24          1 B 5/60/09 30  6/5/09
ID=1 DRUG=B START_DT=. DAYS_SUPP=30 END_DT=2009-06-05 _ERROR_=1 _N_=2
NOTE: The data set WORK.HAVE has 2 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


22  !           ;
25    ;
26
27    data days;
28      set have;
29      dum = 1;
30      do day = start_dt to end_dt;
31        output;
32      end;
33      format day yymmdd10.;
34    run;

ERROR: Invalid DO loop control information, either the INITIAL or TO expression is missing or the BY expression is missing, zero, or
       invalid.
ID=1 DRUG=B START_DT=. DAYS_SUPP=30 END_DT=2009-06-05 dum=1 day=. _ERROR_=1 _N_=2

You can trap those cases and not execute the DO loop when there are missing values.

if n(start_dt,end_dt)=2 then do day = start_dt to end_dt;
macro_2349
Calcite | Level 5
Thank you so much! There are several patients in my analyses who had not received any medication who were causing the error. This code executed perfectly.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 7 replies
  • 1387 views
  • 0 likes
  • 6 in conversation