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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 802 views
  • 0 likes
  • 4 in conversation