BookmarkSubscribeRSS Feed
karen_e_wallace
Obsidian | Level 7

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
10 REPLIES 10
Reeza
Super User

  IF FIRST.MEMBER_AMISYS_NBR THEN do;

MEMID = MEMID + 1;  /* autoincrement based upon new Amisys # */ 

visit=0;

end;

 

karen_e_wallace
Obsidian | Level 7

Thanks for the code...the MemID counter is working but the Visit variable is set to zero for all the rows.

Reeza
Super User

Did you change your other VISIT line? If you didn't change it, this should have worked fine.

 

Please post your full new code.

karen_e_wallace
Obsidian | Level 7

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;

Reeza
Super User

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.

karen_e_wallace
Obsidian | Level 7

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;

Kurt_Bremser
Super User

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;
karen_e_wallace
Obsidian | Level 7

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;

Kurt_Bremser
Super User

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 😉

karen_e_wallace
Obsidian | Level 7

Thanks...sorry didn't mean to shout

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 10 replies
  • 1480 views
  • 0 likes
  • 3 in conversation