BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Amali6
Quartz | Level 8

Hi everyone,

I tried proc report for calculating the total no of repeated guest to a specific hotel in my dataset which has 119390 observations in total. I got a longer output, is there any way to reduce the size of the output rather than scrolling the page too much down to see the result? Could you provide solution for this please?

Amali6_0-1589587005088.pngAmali6_1-1589587027953.png

Here  i would like to show only the total 2032 using the same proc report, is there any way to do this?

proc report data=hotel.Hotel_bookings;
 column hotel is_repeated_guest;
 where hotel='City Hotel' and 
       is_repeated_guest=1;
 rbreak after/summarize style=[font_weight=bold];
 title'No of repeated guest to City Hotel';
 run;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Input data is often helpful.

 

 

If you want to count (or sum ) within a specific value then you would use a Define statement to tell the Proc that is what you want:

proc report data=hotel.Hotel_bookings;
 column hotel is_repeated_guest;
 where hotel='City Hotel' and 
       is_repeated_guest=1;
 define hotel / group;
 rbreak after/summarize style=[font_weight=bold];
 title'No of repeated guest to City Hotel';
 run;

Since your where statement will only have one value of hotel there really is no reason for an "rbreak after".
If you are running this without the where I would suggest not including the Rbreak and see what the result looks like.

 

Or quite possibly you might want to summarize your data and use proc print.

 

View solution in original post

4 REPLIES 4
ballardw
Super User

Input data is often helpful.

 

 

If you want to count (or sum ) within a specific value then you would use a Define statement to tell the Proc that is what you want:

proc report data=hotel.Hotel_bookings;
 column hotel is_repeated_guest;
 where hotel='City Hotel' and 
       is_repeated_guest=1;
 define hotel / group;
 rbreak after/summarize style=[font_weight=bold];
 title'No of repeated guest to City Hotel';
 run;

Since your where statement will only have one value of hotel there really is no reason for an "rbreak after".
If you are running this without the where I would suggest not including the Rbreak and see what the result looks like.

 

Or quite possibly you might want to summarize your data and use proc print.

 

ed_sas_member
Meteorite | Level 14

Hi @Amali6 

 

What about using a PROC FREQ:

 

proc freq data=hotel_bookings;
	where hotel = 'City Hotel' and is_repeated_guest = 1;
	tables is_repeated_guest / nocum nopercent;
run;
RichardDeVen
Barite | Level 11

A Proc REPORT variable DEFINED with feature / GROUP will cause summary statistics to be computed. The default statistic is SUM, perfect for 'counting' a 0/1 flag variable.

 

Example:

 

data have_apriori_summary(keep=hotel_id guest_id is_repeated_guest);
  call streaminit (123);
  do hotel_id = 1 to 10;
    do index = 1 to 100;
      guest_id + 1;
      is_repeated_guest = rand ('uniform') < 0.40;
      output;
    end;
  end;
run;

proc report data=have_apriori_summary;
  title "Guest retention results from apriori per guest summary";
  column hotel_id is_repeated_guest;

  define hotel_id / group;
  define is_repeated_guest / 'Repeated Guests';

  where hotel_id in (1,3,4);
run;

 

Output

RichardADeVenezia_0-1589638708180.png

 

Consider a slightly different scenario:

Suppose the data set contains transactional information, such as CHECK_IN_DATE, ROOM_ID, and GUEST_ID and the REPEAT flag is a marker for some customer service action at the desk.  Taking a sum of the flag values over the transactions will NOT give the number of DISTINCT guests, the SUM will be the number of repeated guest visits.  You will need to reduce the transaction data to a summary in order to count the number of distinct guests.

 

Example:

 

data have_checkin_log(keep=hotel_id room_id date guest_id is_repeated_guest);
  call streaminit (123);
  array tracker(7500) _temporary_;
  do index = 1 to dim(tracker);
    tracker(index) = rand('uniform') < 0.15;
  end;
  do hotel_id = 1 to 10;
    do room_id = 1 to 50;
      do date = '01jan2020'd to '31jan2020'd;
        guest_id = rand('integer',1,7500);
        is_repeated_guest = tracker(guest_id);
        output;
      end;
    end;
  end;
  format date yymmdd10.;
run;

proc sql;
  create table repeated_guests_summary as 
  select 
    hotel_id,
    guest_id,
    is_repeated_guest,
    count(*) as repeated_visits_count
  from have_checkin_log
  where is_repeated_guest
  group by hotel_id, guest_id
  ;
quit;

proc report data=repeated_guests_summary;
  title "Repeated Guests and Visits";
  column hotel_id is_repeated_guest repeated_visits_count;

  define hotel_id / group;
  define is_repeated_guest / 'Repeated Guests';

  where hotel_id in (1,3,4);
run;

Output

RichardADeVenezia_2-1589640782673.png

 

 

 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 608 views
  • 4 likes
  • 5 in conversation