SAS Studio, Programming 2, Lesson 2 Summarizing Data Challenge Practice: Determining Maximum Amounts
Question: Why am I not seeing the same number as the solution for question 2? I typed the same code, however, in my output table, the column for TrafficMax all result in the value '0'
Question 2 of the challenge practice asks: "What is the value of TrafficMax in row 4, and why?"
Solution: TrafficMax retains the value of 1,447 from the previous row because the 772 value of Count in row 4 is not greater than the current value of TrafficMax."
Create a table, cuyahoga_maxtraffic, from the pg2.np_monthlytraffic table. Use the following specifications:
- Include only rows where ParkName is equal to Cuyahoga Valley NP.
- Create three columns: TrafficMax, MonthMax, and LocationMax. Initialize TrafficMax to 0.
- If the current traffic count is greater than the value in TrafficMax, then:
- set the value of TrafficMax equal to Count
- set the value of MonthMax equal to Month, and
- set the value of LocationMax equal to Location
- Format the Count and TrafficMax columns so that values are displayed with commas.
- Keep only the Location, Month, Count, TrafficMax, MonthMax, and LocationMax columns in the output table.
- Submit the program and examine the ouput data.
data cuyahoga_maxtraffic;
set pg2.np_monthlyTraffic;
where ParkName = 'Cuyahoga Valley NP';
retain TrafficMax 0 MonthMax LocationMax;
if Count>TrafficMax then do;
TrafficMax=Count;
MonthMax=Month;
LocationMax=Location;
end;
format Count TrafficMax comma15.;
keep Location Month Count TrafficMax MonthMax LocationMax;
run;
Thank you.