From a large dataset, I am interested in counting the member ID and categorizing the number of visits based upon the DOS_Start (SAS Enterprise 7.1 (7.100.0.1966) (64-bit).
There are occasions where there are different claim numbers that have the same DOS.
An example in this data is that the member 0001 had multiple claims in the ER for DOS_Start of 4/11/17; however, I only want to count this as one visit to the ER for this analysis.
In this newest iteration of code, I'm able to get the member ID correct but not the visit. When the member ID is 0002, the visit counter should reset to 1; however, it is continuing to auto-increment as if it is still member ID 0001.
Thank you in advance for your help! - Karen
Current code:
PROC SORT DATA=WORK.SAMPLE OUT=WORK.SORTED;
BY MEMBER_AMISYS_NBR DOS_Start;
RUN;
DATA WANT;
SET WORK.SORTED;
BY MEMBER_AMISYS_NBR DOS_Start;
Format DOS_Start MMDDYY10.;
RETAIN MEMID VISIT 0;
IF FIRST.MEMBER_AMISYS_NBR THEN MEMID = MEMID + 1; /* autoincrement based upon new Amisys # */
IF FIRST.DOS_START THEN DO;
VISIT=VISIT+1; /* this works to increment visits based upon date */
END;
RUN;
Current Output:
MEMBER_AMISYS_NBR | CLAIM_NBR | DOS_Start | MCC1 | MCC2 | MEMID | VISIT |
0001 | 12 | 03/15/2017 | Primary Care | Primary Care | 1 | 1 |
0001 | 12 | 03/15/2017 | Primary Care | Primary Care | 1 | 1 |
0001 | 84 | 03/16/2017 | Hospital Outpatient | Outpatient- Other | 1 | 2 |
0001 | 84 | 03/16/2017 | Hospital Outpatient | Outpatient- Other | 1 | 2 |
0001 | 43 | 03/17/2017 | Hospital Outpatient | Outpatient- Other | 1 | 3 |
0001 | 66 | 04/11/2017 | Emergency Room | ED Other | 1 | 4 |
0001 | 22 | 04/11/2017 | Emergency Room | Emergency Room | 1 | 4 |
0001 | 22 | 04/11/2017 | Emergency Room | Emergency Room | 1 | 4 |
0001 | 22 | 04/11/2017 | Emergency Room | Emergency Room | 1 | 4 |
0001 | 22 | 04/11/2017 | Emergency Room | Emergency Room | 1 | 4 |
0001 | 22 | 04/11/2017 | Emergency Room | Emergency Room | 1 | 4 |
0001 | 22 | 04/11/2017 | Emergency Room | Emergency Room | 1 | 4 |
0001 | 22 | 04/11/2017 | Emergency Room | Emergency Room | 1 | 4 |
0001 | 22 | 04/11/2017 | Emergency Room | Emergency Room | 1 | 4 |
0001 | 22 | 04/11/2017 | Emergency Room | Emergency Room | 1 | 4 |
0001 | 22 | 04/11/2017 | Emergency Room | Emergency Room | 1 | 4 |
0001 | 22 | 04/11/2017 | Emergency Room | Emergency Room | 1 | 4 |
0001 | 22 | 04/11/2017 | Emergency Room | Emergency Room | 1 | 4 |
0001 | 22 | 04/11/2017 | Emergency Room | Emergency Room | 1 | 4 |
0001 | 44 | 04/11/2017 | Emergency Room | ED Other | 1 | 4 |
0002 | 6 | 08/18/2017 | Primary Care | Primary Care | 2 | 5 |
0002 | 6 | 08/18/2017 | Primary Care | Primary Care | 2 | 5 |
IF FIRST.MEMBER_AMISYS_NBR THEN do;
MEMID = MEMID + 1; /* autoincrement based upon new Amisys # */
visit=0;
end;
Thanks for the code...the MemID counter is working but the Visit variable is set to zero for all the rows.
Did you change your other VISIT line? If you didn't change it, this should have worked fine.
Please post your full new code.
DATA want;
SET WORK.SORTED;
BY MEMBER_AMISYS_NBR DOS_Start;
Format DOS_Start Admit_Dt MMDDYY10.;
RETAIN MEMID VISIT 0;
IF FIRST.MEMBER_AMISYS_NBR THEN DO; /* autoincrement based upon new Amisys # */
MEMID=MEMID+1;
VISIT=0; /* this works to increment visits based upon date */
END;
RUN;
Add back the increment for visit like I mentioned initially. You don't have to take out any code, you need to ADD some in.
Reeza,
Apologies I'm not understanding well how to re-order this code properly...please bear with me 🙂
Was it to add in two first. variables to auto-increment visit? Clearly the below isn't correct on my part.
Appreciate your help!
...
RETAIN MEMID VISIT 0;
IF FIRST.MEMBER_AMISYS_NBR THEN DO; /* autoincrement based upon new Amisys # */
MEMID=MEMID+1;
VISIT=0; /* this works to increment visits based upon date */
END;
IF FIRST.MEMBER_AMISYS_NBR THEN DO; /* autoincrement based upon new Amisys # */
MEMID=MEMID+1;
VISIT=VISIT+1; /* this works to increment visits based upon date */
END;
Try this:
data want;
set work.sorted;
by MEMBER_AMISYS_NBR DOS_Start;
format DOS_Start MMDDYY10.;
retain MEMID VISIT 0;
if first.MEMBER_AMISYS_NBR
then do;
MEMID + 1;
VISIT = 0;
end;
if first.DOS_START then VISIT + 1;
run;
Thank you Kurt...I tweaked that a bit and now is working as:
...
RETAIN MEMID VISIT 0;
IF FIRST.MEMBER_AMISYS_NBR THEN DO;
MEMID + 1; /* autoincrement based upon new Amisys # - correct */
VISIT = 0;
END;
IF FIRST.DOS_START THEN DO;
VISIT=VISIT+1; /* this works to increment visits based upon date */
END;
A single statement does not need a do/end in a then or else branch.
And you don't need to shout at the SAS interpreter, it understands lowercase perfectly well, and for us humans it's more readable 😉
Thanks...sorry didn't mean to shout
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.