DATA Step, Macro, Functions and more

Grouping

Reply
Contributor
Posts: 34

Grouping

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;

Respected Advisor
Posts: 3,908

Re: Grouping

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.

Contributor
Posts: 34

Re: Grouping

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 ;
Super User
Posts: 17,963

Re: Grouping

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

 

 

Contributor
Posts: 34

Re: Grouping

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;
Super User
Posts: 17,963

Re: Grouping


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. 

 

 

Ask a Question
Discussion stats
  • 5 replies
  • 244 views
  • 0 likes
  • 3 in conversation