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

I have a table that looks like this :

 

data work.hotel;
Length Hotel_Name $9 Class $1 ;
INPUT Hotel_Name $ Class $ Country $ PRICE ;
CARDS ;
Appolpon A Greece 390
Caravel B Greece 468
Christina A Greece 427
Economy B Greece 369
EdenBeach A Greece 499
HanikianBeach C Greece 526
MarinaBeach C Greece 587
Xenia C Greece 534
Agdal B Maroc 447
Almohades B Maroc 482
Atlas A Maroc 511
AtlasArnadi C Maroc 532
Chems C Maroc 450
Dunes A Maroc 569
AlfaMa B Portu 646
AppDo B Portu 652
DELagos C Portu 802
Madeira A Portu 761
Reid's A Portu 1101
AbouSofiane A Tunis 434
Asdrubal A Tunis 489
Colombes B Tunis 436
Darnaour B Tunis 399
Djerba C Tunis 477
Mimosa C Tunis 375
Omarit B Tunis 486
;
run;

 

I'm trying to create a table with the countries as rows, the class as column and the name of the hotel with the minimum price for each pair.

 

Something like this :

        A           B           C
Greece  Appolpon    Caravel     Marinabeach
Portu   Madeira     Appdo       Delagos
Maroc   Atlas       Agdal       Chems

I tried with proc tabulate and proc transpose but couldn't get exactly the result i'm looking for.

 

Thank you for your help 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Take the top record first and then try your transpose. 

 

  1. Sort by Country, class, price
  2. Sort by Country, Class - NODUPKEY which will keep the top record
  3. Use PROC TRANSPOSE to flip it wide. 


Long to Wide:
https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/



@jo_pariseau wrote:

I have a table that looks like this :

 

data work.hotel;
Length Hotel_Name $9 Class $1 ;
INPUT Hotel_Name $ Class $ Country $ PRICE ;
CARDS ;
Appolpon A Greece 390
Caravel B Greece 468
Christina A Greece 427
Economy B Greece 369
EdenBeach A Greece 499
HanikianBeach C Greece 526
MarinaBeach C Greece 587
Xenia C Greece 534
Agdal B Maroc 447
Almohades B Maroc 482
Atlas A Maroc 511
AtlasArnadi C Maroc 532
Chems C Maroc 450
Dunes A Maroc 569
AlfaMa B Portu 646
AppDo B Portu 652
DELagos C Portu 802
Madeira A Portu 761
Reid's A Portu 1101
AbouSofiane A Tunis 434
Asdrubal A Tunis 489
Colombes B Tunis 436
Darnaour B Tunis 399
Djerba C Tunis 477
Mimosa C Tunis 375
Omarit B Tunis 486
;
run;

 

I'm trying to create a table with the countries as rows, the class as column and the name of the hotel with the minimum price for each pair.

 

Something like this :

        A           B           C
Greece  Appolpon    Caravel     Marinabeach
Portu   Madeira     Appdo       Delagos
Maroc   Atlas       Agdal       Chems

I tried with proc tabulate and proc transpose but couldn't get exactly the result i'm looking for.

 

Thank you for your help 


 

View solution in original post

5 REPLIES 5
Reeza
Super User

Take the top record first and then try your transpose. 

 

  1. Sort by Country, class, price
  2. Sort by Country, Class - NODUPKEY which will keep the top record
  3. Use PROC TRANSPOSE to flip it wide. 


Long to Wide:
https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/



@jo_pariseau wrote:

I have a table that looks like this :

 

data work.hotel;
Length Hotel_Name $9 Class $1 ;
INPUT Hotel_Name $ Class $ Country $ PRICE ;
CARDS ;
Appolpon A Greece 390
Caravel B Greece 468
Christina A Greece 427
Economy B Greece 369
EdenBeach A Greece 499
HanikianBeach C Greece 526
MarinaBeach C Greece 587
Xenia C Greece 534
Agdal B Maroc 447
Almohades B Maroc 482
Atlas A Maroc 511
AtlasArnadi C Maroc 532
Chems C Maroc 450
Dunes A Maroc 569
AlfaMa B Portu 646
AppDo B Portu 652
DELagos C Portu 802
Madeira A Portu 761
Reid's A Portu 1101
AbouSofiane A Tunis 434
Asdrubal A Tunis 489
Colombes B Tunis 436
Darnaour B Tunis 399
Djerba C Tunis 477
Mimosa C Tunis 375
Omarit B Tunis 486
;
run;

 

I'm trying to create a table with the countries as rows, the class as column and the name of the hotel with the minimum price for each pair.

 

Something like this :

        A           B           C
Greece  Appolpon    Caravel     Marinabeach
Portu   Madeira     Appdo       Delagos
Maroc   Atlas       Agdal       Chems

I tried with proc tabulate and proc transpose but couldn't get exactly the result i'm looking for.

 

Thank you for your help 


 

jo_pariseau
Fluorite | Level 6
Thank you, with your advices it finally worked.
Sajid01
Meteorite | Level 14

@jo_pariseau 
Could you mind posting the code that worked?

jo_pariseau
Fluorite | Level 6
proc sort data=lib.hotels2 out=lib.hotels3;
by coutry class price;
run;

proc sort data=lib.hotels3 out=lib.hotels4 NODUPKEY;
by coutry class;
run;

proc transpose data=devoir.hotels3 out=devoir.hotels4;
by country ;
id class;
run;
Sajid01
Meteorite | Level 14

Thanks

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 475 views
  • 2 likes
  • 3 in conversation