I am creating a dataset for an Excel pivot table with respect to revenue from airlines. There are cases where an airline has no flights for a month, and hence no revenue. I'd like there to be a forced count of 0 for the month and 0 for revenue. I have this code from proc means:
PROC MEANS DATA=EGTASK.REVENUE
NOPRINT CHARTYPE
NOLABELS
NWAY
SUM NONOBS ;
VAR amount;
CLASS name / ORDER=UNFORMATTED ASCENDING;
BY Year Month;
OUTPUT OUT=EGTASK.REVENUE_BY_CLIENT_MONTHLY
SUM()=
/ AUTONAME AUTOLABEL WAYS INHERIT
;
RUN;
What ends up happening is that the top 6 clients (called name above) from the previous year are tracked during the current year. If there is a month where there are no observations for a client (called name) then they should be set to 0 for both flight counts and revenue totals.
thanks
If you want to use Proc Means then you will have to add the zero values into the data set if you want the mean to treat the value as 0 for means calculations.
Or perhaps you might want the year and month as class variables and use COMPLETETYPES on the proc statement to force values for months without any actual observations to appear in the output. Not really very clear what you actually expect.
CLASSDATA dataset does it! Thanks!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.