BookmarkSubscribeRSS Feed
mkeintz
PROC Star

You have three variables identifying three provider types, and four variables identifying four service types.  So imagine you read in each of your current observations, and making twelve observations from it (corresponding to 3 rows and 4 columns).  The resulting data set, NEED, could have these 3 variables:

 

  1. Provider_type    (with values "Doctor", "Nurse", "Assistant_Physician")  (i.e. the var name of the indicated provider variable)
  2. Service_type ("Consultation .... Procedure")       -  var name of the indicated service variable
  3. MY_FREQ  (the sum of values of the indicated provider and service

So you would 12 times as many observations as you start with.  But you could now do a crosstab of provider_type by service_type, and tell the sas procedure to weight each record by MY_FREQ.

 

Something like

 

   

proc tabulate data=need noseps order=data;
  freq my_freq;
  tables
     provide_type  all='Total' ,
     service_type * N * f=12.0;
run;

 

So now, you need to determine how to create data set NEED.  Consider using two arrays:

  1. An array for rows  (variables doctor, nurse, assistant_physician
  2. An array for cols  (consultation ... procedure)

You can do nested loops, loop through the column array inside a loop over the row array.  Set MY_FREQ to the sum of values for the row variable and the col variable, and then OUTPUT.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 15 replies
  • 3516 views
  • 2 likes
  • 5 in conversation