BookmarkSubscribeRSS Feed
azee007
Calcite | Level 5

I am trying to group data of one variable RoomType have 4 types of views , and have to group them in my result . But am not getting required result. Please guide.

 

 

Data formate3;
set format;
length Group $8;
by RoomType;
Group= Basic $20 for Basic room with view or no view;
Group = Suite $30 for Suites and Luxury suites;
Group = Luxury $30 for Luxury rooms ;
run;

proc print data=format3;
run;

5 REPLIES 5
Patrick
Opal | Level 21

There are several things wrong with your code.

 

Please provide working data step code which creates sample data for table "format" and then show us how the desired output should look like.

azee007
Calcite | Level 5
I just wanna know if there is a column RoomType having observations of few types of views and want to group them into 3 variables basic , suit and luxury. The below group is the requirement from the dataset.

Group= Basic for Basic room with view or no view;
Group = Suite for Suites and Luxury suites;
Group = Luxury for Luxury rooms ;
Reeza
Super User

Ok. That isn't valid SAS code and you haven't provided enough information for us to provide suggestions. 

 

Heres a quick primer on how to recode variables in SAS. Just note that if your working with strings you need to enclose them in quotation marks - see your previous question. 

 

http://www.ats.ucla.edu/stat/sas/modules/vars.htm

 

UCLA tutorials 

http://www.ats.ucla.edu/stat/sas/modules/default.htm

 

And most important - How to ask a good question. Please make an attempt to follow these guidelines. 

http://stackoverflow.com/help/how-to-ask

 

 

azee007
Calcite | Level 5
Dear Reeze , I have already read all the material . But nothing is particular related to my problem. I have written code as below . But facing issues.

Data formate3;
set format;
length Group $8;
by RoomType;
if type in ('Basic no view','Basic w/view') then Group='Basic';
else if type in ('Suite','Deluxe suite') then Group='Suite';
else Group='Luxury';
run;
Reeza
Super User

@azee007 wrote:
Dear Reeze , I have already read all the material . But nothing is particular related to my problem. I have written code as below . But facing issues.


We're not psychic. What does 'facing issues' mean? 

 

1. Are there errors in your log? 

2. Are results not what you expect? In not, how are they different? Show what you have, what you get, and what you want. 

3. From your last question recall string comparisons are case sensitive.

4. Note that you're referencing FORMAT dataset. In your last questions you had progressed to. FORMAT2. If you want your code to build upon each other make sure to reference correct dataset. Also, since FORMAT has a specific meaning in SAS I would recommend avoiding that word as a dataset name to avoid any confusion. 

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 934 views
  • 0 likes
  • 3 in conversation