BookmarkSubscribeRSS Feed
fordcr2
Obsidian | Level 7

Hello, 

 

I am trying to calculate a percentage of health care providers that log into an online platform within a week of their patients logging in. I have a dataset with the date that the patient logged in as well as the dates in which the providers have logged in. This dataset will end up being very large (as the study will go on for 2 years with over 150 participants), so I need to figure out how to automate a SAS code to calculate weekly intervals based off of the date that the patients logged in. Not all patients log in on the same day, so I can't figure out how to do this. I found this macro online which makes weekly intervals, but I would need these intervals to be based off of a variable (participant_startdate) instead of a date that I could put in like this '24Jan2019'. I hope that makes sense!

 

%let start='24Jan2019'd;
%let end=date();

data set_weeks;
retain fmtname 'weeks';
start=&start;
end=start+6;
label="Week: "||PUT(start, mmddyy10.)||" - "||PUT(end, mmddyy10.);
OUTPUT;
DO UNTIL (end > &end);
start=start+7;
end=end+7;
label="Week: "||PUT(start, mmddyy10.)||" - "||PUT(end, mmddyy10.);
OUTPUT;
end;
keep fmtname start end label;
format start end mmddyy10.;
run;

 

16 REPLIES 16
PaigeMiller
Diamond | Level 26

Instead of setting a macro variable with a date at the start of your program, you use a SAS data set (using the SET command) and then do the exact same calculations using the date the patient logged in that is in the data set.

--
Paige Miller
fordcr2
Obsidian | Level 7

So I replaced %let start='24Jan2019',d; with %let start=participant_startdate; and put data set_weeks; set all_ids; (this is the dataset)

and it keeps crashing SAS. I get an error "OUT OF RESOURCES. Select: R. Retry, N. Tell procedure/DATA step no more resources, C. Cancel submitted statements, T. Terminate SAS"?

PaigeMiller
Diamond | Level 26

First, as I envision the solution, there are no macro variables at all. Everything is computed inside the DATA step, based on whatever the variable name is that contains the date when the patient logged on.

 

If you are getting an out of resources message, we need to know how many records are in this data set ALL_IDS, and how many variables as well.

 

 

--
Paige Miller
fordcr2
Obsidian | Level 7

As of right now, there are 107 observations and 11 variables from all_ids, but that number will grow as more are enrolled in the study. I would love to not use a macro if possible, but I have not figure out how to calculate a weekly interval variable. I would use the participant_startdate variable and have to count out 7 days from that date in order to get the weekly interval that I need for each participant. I have matched participants with their assigned providers so I can compare the provider login date with the patient login date. 

PaigeMiller
Diamond | Level 26

Use participant_startdate instead of &start.

 

You shouldn't have resource problems with a data set of that size.

--
Paige Miller
fordcr2
Obsidian | Level 7

Is there an alternative way of calculating this? I keep getting the same error message. 

PaigeMiller
Diamond | Level 26

I think you have to figure out this Resources issue, rather than try to re-program the code. This code, as far as I can see, should not be the problem. But, just in case, please show us the actual code you are using.

--
Paige Miller
fordcr2
Obsidian | Level 7

This is the code I am using that I keep getting the error for:

 

%let end=date();

data weeks;
set all_ids;
retain fmtname 'weeks';
start=participant_startdate;
end=start+6;
label="Week: "||PUT(start, mmddyy10.)||" - "||PUT(end, mmddyy10.);
OUTPUT;
DO UNTIL (end > &end);
start=start+7;
end=end+7;
label="Week: "||PUT(start, mmddyy10.)||" - "||PUT(end, mmddyy10.);
OUTPUT;
end;
keep fmtname start end label;
format start end mmddyy10.;
run;
end;

PaigeMiller
Diamond | Level 26

So, as I said, you don't need (and should not have) any macro variables at all.

 

 

 

data weeks;
set all_ids;
retain fmtname 'weeks';
start=participant_startdate;
end=start+6;
label="Week: "||PUT(start, mmddyy10.)||" - "||PUT(end, mmddyy10.);
OUTPUT;
DO UNTIL (end > date());
start=start+7;
end=end+7;
label="Week: "||PUT(start, mmddyy10.)||" - "||PUT(end, mmddyy10.);
OUTPUT;
end;
keep fmtname start end label;
format start end mmddyy10.;
run;
end;

 

--
Paige Miller
fordcr2
Obsidian | Level 7

Ok that makes sense... but how would you suggest I edit the code then? I am a little confused as to how to resolve this. 

PaigeMiller
Diamond | Level 26

I provided code that ought to work.

--
Paige Miller
fordcr2
Obsidian | Level 7

Sorry, didn't realize that was different. I am still getting the out of resources error message. I have no idea why. 

PaigeMiller
Diamond | Level 26

The only thing I can think of is that the data is not how you described it. Can you show us a portion of the data you are working with?

--
Paige Miller
fordcr2
Obsidian | Level 7

I don't think I can share the data but this is the full error I am getting from the log:

 

601 data weeks;
602 set all_ids;
603 retain fmtname 'weeks';
604 start=participant_startdate;
605 end=start+6;
606 label="Week: "||PUT(start, mmddyy10.)||" - "||PUT(end, mmddyy10.);
607 OUTPUT;
608 DO UNTIL (end > date());
609 start=start+7;
610 end=end+7;
611 label="Week: "||PUT(start, mmddyy10.)||" - "||PUT(end, mmddyy10.);
612 OUTPUT;
613 end;
614 keep fmtname start end label;
615 format start end mmddyy10.;
616 run;

ERROR: Insufficient space in file WORK.WEEKS.DATA.
ERROR: File WORK.WEEKS.DATA is damaged. I/O processing did not complete.
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
1 at 605:10 129728360 at 609:12 129728360 at 610:8
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 2 observations read from the data set WORK.ALL_IDS.
WARNING: The data set WORK.WEEKS may be incomplete. When this step was stopped there were
129728363 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 50.60 seconds
cpu time 34.04 seconds


617 end;
---
180

ERROR 180-322: Statement is not valid or it is used out of proper order.

 

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!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 16 replies
  • 2572 views
  • 0 likes
  • 3 in conversation