I am trying to get the maximum no of passengers in greyhound and megabus & abc routes to different cities .
If i take one city Washington-WA and there are many buses going in different years to WA with different no of passenger(WAP).I have 20,000 of data set , just giving a short form,As my code is not working.
Bus WAP Year
Greyhound 4220 2000
Megabus 3200 2000
abc 15 00 2000
Greyhound 4200 2001
Megabus 3290 2001
abc 1598 2001
Greyhound 5200 2002
Megabus 3250 2002
abc 2000 2002
How to have one observation for the Bus variable with max passengers for the Year 2001.
I want to create a variable that represents the no of passengers per Bus for Year 2001 and which Bus. If anybody can help , and also can help me change that code to macro so that i can use any number of city, as i have 16 cities data. I will be very thanksful if anybody help me in getting the code right.
proc means nolabels data=WAP Max;
class Bus Year;
output out=maxp;
run;
proc print data=maxp;
where _stat_= MAX Year=2001;
var Bus Year WAP;
run;
I am having a bit of trouble understanding this, could you post what your desired output looks like? 🙂
data have;
input bus :$20. wap year;
cards;
Greyhound 4220 2000
Megabus 3200 2000
abc 1500 2000
Greyhound 4200 2001
Megabus 3290 2001
abc 1598 2001
Greyhound 5200 2002
Megabus 3250 2002
abc 2000 2002
;
run;
proc sql;
create table want as
select bus, wap
from have
where year = 2001
having wap = max(wap)
;
quit;
This IS valid Base SAS code, believe me. Just run it.
And if you tell me what needs to be made dynamic, I can at least give you hints how to do it.
To get a good answer to your question, follow some general tips on posting:
- Post test data, in the form of a datastep
- Post example output you require
- Try to keep requirements to exactly what the question is about
For the legitimate sas data step code , could like: proc sort data=have out=temp; by bus year wap; run; data want; set temp; by bus year; if last.year; run;
You have not yet responded with an actual example of the result you wish to generate, so we are all trying to read your mind. Here is my guess. It uses the PROC MEANS that you have chosen.
Notes
proc means data=wap nway noprint;
class year;
var wap;
output out=want maxid(wap(bus))=maxwapbus max=maxwap;
run;
proc print data=want;
var year maxwapbus maxwap;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.