BookmarkSubscribeRSS Feed
Aar684
Calcite | Level 5
data kva;
infile 'C:\Documents and Settings\dubauaw\Desktop\Jims KVA 2009\Rate 56 (Group 1)Cal.csv' dsd missover LRECL=1000000;
length account $9. meter $9. channel $12. LRID $15. name $25. meteragain $9.;
input account $ meter $ regtype $ channel $ LRID $ name $ meteragain $ type1 $ type2 $ date hour1-hour24;
informat date mmddyy9.;
run;


data usagesum;
set kva end = eof;
retain maxuse maxuse12_8 maxuse_other max_offpeak ;
if (day(date) = 1 or last.account) and not (_n_ = 1) then do;
month = month(lag(date));
output;
maxuse = 0;
maxuse12_8=0;
maxuse_other=0;
max_offpeak =0;
end;
maxuse = max(maxuse , max(of hour1 - hour24));
maxuse12_8 = max(maxuse12_8 , max(of hour12 - hour20));
maxuse_other = max(of maxuse_other , max(max(of hour1 - hour11),max(of hour21-hour24)));
if weekday(date) NE 2-6 then do;
max_offpeak = max(of maxuse_other, max(of hour1-hour24));
end;
run;


There is my code. My only problem now is the first account is missing a month. The month variable works like it should but the first account skips a month. Not sure why? That is to say that the month variable works all the way through, but something isn't lining up. Message was edited by: Aar684
deleted_user
Not applicable
What is the month variable for?
Aar684
Calcite | Level 5
just to keep track of the month I believe.

my problem is the first account only does 11 months of peaks where as the rest of the data set/accounts have all 12, any ideas?
Flip
Fluorite | Level 6
if _n_ = 1 then month = month(date);
deleted_user
Not applicable
Have you heard of the software development lifecycle?

Basically it teaches us that the most important thing is to get the requirements right from the start. This is a case in point. Because you asked for something at the start and then changed your requirements the program is becoming a mess.

If you fix that then other things go wrong and it just takes a whole lot of messing around. I'll try:

data usagesum;
set kva end = eof;
retain maxuse maxuse12_8 maxuse_other max_offpeak;
month = month(date);
*if its the first of the month of the first observation for the account;
*set all the reained varaibles to zero, to start again;
if (day(date) = 1 or first.account) then do;
maxuse = 0;
maxuse12_8=0;
maxuse_other=0;
max_offpeak =0;
end;
maxuse = max(maxuse , max(of hour1 - hour24));
maxuse12_8 = max(maxuse12_8 , max(of hour12 - hour20));
maxuse_other = max(of maxuse_other , max(max(of hour1 - hour11),max(of hour21-hour24)));
if weekday(date) NE 2-6 then do;
max_offpeak = max(of maxuse_other, max(of hour1-hour24));
end;
*if it is the last record for the account or the last day of the month;
*output the observation;
if last.account or month ne month(date+1) then output;
run;
Aar684
Calcite | Level 5
I know this usually requires much more planning and time. I am being shipped off to another work center for 4 months starting Monday of next week and I needed to have something done in 2 days I had left before I left. I appreciate all the help that everyone has provided.
deleted_user
Not applicable
Well good luck with the next 4 months and credit due for finding out that weekdays in SAS start on a Sunday. Gets me every time.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 21 replies
  • 3737 views
  • 0 likes
  • 4 in conversation