BookmarkSubscribeRSS Feed
Juli4
Calcite | Level 5

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.

2 REPLIES 2
mharding
SAS Employee

Hi Juli4,

Your code does match the solution, and to double check I copied your code, ran it and I did get the correct results.  There could be an issue with the input table.

 

Did you see the following NOTE in your log?

NOTE: There were 384 observations read from the data set PG2.NP_MONTHLYTRAFFIC.
WHERE ParkName='Cuyahoga Valley NP';

Thank you

Mary

Juli4
Calcite | Level 5
Hi Mary,

Thank you for the prompt response. I did receive the same NOTE in my log.

Upon closer look, it was a syntax error.
The code I ran was
data cuyahoga_maxtraffic;...

TrafficCount=Count;

instead of
TrafficMax=Count;

I have the correct solution now, thank you so much.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
LIBNAME 101

Follow along as SAS technical trainer Dominique Weatherspoon expertly answers all your questions about SAS Libraries.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 886 views
  • 2 likes
  • 2 in conversation