BookmarkSubscribeRSS Feed
jessho
Calcite | Level 5

Hi,

I am trying to create two different count variables -- PHI_visits (ie. visits when insurance=1) and Medicaid_visits (i.e. visits when insurance=0) -- to count the number of unique patient visits (patcode) with each unique provider (ID) that are with a privately insured patients and Medicaid-covered patients, respectively.  However, I am noticing that the code I am using is creating two count variables that seems to not be counting properly, and I cannot seem to figure out why.

 

Here is my code:

Data HAmod;
Set IN.HA;
retain ID insurance patcode Medicaid_visits PHI_visits;
by ID;
if first.ID then do;
Medicaid_visits=0;
PHI_visits=0;
end;
if insurance=0 then Medicaid_visits+1;
else if insurance=1 then PHI_visits+1;
Run;

 

However, when I check the results using proc print, this produces a table as follows:

 

ID PATCODE insurance Medicaid_visits PHI_visits
6510101
6515103
7620101
1119010
12430010
13831010
16635101
16647103
17611101
19624010
21850101
24216101
24221103

 

It should instead look like below if PHI_visits and Medicaid_visits are counting correctly:

However, when I check the results using proc print, this produces a table as follows:

 

ID PATCODE insurance Medicaid_visits PHI_visits
6510101
6515102
7620101
1119010
12430010
13831010
16635101
16647102
17611101
19624010
21850101
24216101
24221102

 

Would appreciate any help or suggestions. Thanks!

3 REPLIES 3
Reeza
Super User

I think the RETAIN statement is the issue. 

Why do you have ID, insurance and patcode in there? 99% of the time data that already exists should not be in the RETAIN STATEMENT

Astounding
PROC Star

Check the incoming data set in.HA.  It probably already contains PHI_visits (and might contain Medicaid_visits as well).  If so, whichever variable(s) already exist should be dropped:

 

set in.HA (drop=PHI_visits Medicaid_visits);

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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