DATA Step, Macro, Functions and more

calculate across hourly data

Accepted Solution Solved
Reply
Contributor
Posts: 56
Accepted Solution

calculate across hourly data

 

I am attempting to calculate "11065865311" across a table of hourly data (hours 1 thru 24).  The array that I tried to setup below does not work, actually errors out.   Is this the correct path?

 

 

 

data work.delete_Main(drop=i);

set work.delete_merging;

array hours {24} 4 H1-H24;

 

do i=(hour1) to 1 by -1;

hours[i]=100;

end;

 

do i=(hour1);

hours[i]=hours/11065865311;

end;

 

output;

run;


Accepted Solutions
Solution
‎10-03-2017 08:04 AM
Trusted Advisor
Posts: 1,399

Re: calculate across hourly data

Posted in reply to tobyfarms

I repeat, your problem is in the NUMERATOR of hours/11065865311.   You need something like hours{I}/11065865311

View solution in original post


All Replies
Trusted Advisor
Posts: 1,399

Re: calculate across hourly data

Posted in reply to tobyfarms

The numerator in the expression

    hours/11065865311

 

 

 should be generating a "error: illegal reference to the array hours" message.

 

You need to specify an index  (i.e. hours{i}, hours{3}, etc.) in the numerator.

Super User
Posts: 10,599

Re: calculate across hourly data

Posted in reply to tobyfarms

If you get an error, posting the log is essential.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 56

Re: calculate across hourly data

Posted in reply to KurtBremser

Agreed, thank you. the log is what @mkeintz mentioned. 

ERROR: Illegal reference to the array hours.

 

The SAS System 08:48 Monday, October 2, 2017

1 %_eg_hidenotesandsource;

5 %_eg_hidenotesandsource;

46

47

48

49 data work.delete_Main(drop=i);

50 /*retain State City Date Dawn Dusk Hour1 Minute1 Hour2 Minute2 ;*/

51 set work.delete_merging;

52

53 array hours {24} 4 H1-H24;

54

55 do i=(hour1) to 1 by -1;

56 hours[i]=100;

57 end;

58

59

60 do i=(hour1);

61 hours[i]=hours/11065865311;

ERROR: Illegal reference to the array hours.

62 end;

63

64 output;

65 run;

NOTE: Missing values were generated as a result of performing an operation on missing values.

Each place is given by: (Number of times) at (Line)Smiley SadColumn).

61:27

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.DELETE_MAIN may be incomplete. When this step was stopped there were 0 observations and 33 variables.

WARNING: Data set WORK.DELETE_MAIN was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

real time 0.01 seconds

cpu time 0.02 seconds

 

Super User
Posts: 10,599

Re: calculate across hourly data

Posted in reply to tobyfarms

Yes, you can't use the whole array in an assignment, you have to use individual members.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 56

Re: calculate across hourly data

Posted in reply to KurtBremser

So am I changing the array script to:

 

array hours {3} H1 - H24;

do i=1 to 3;

hours{i}=hours/11065865311;

 

 

I am not understanding how I the array should be modified.

 

Super User
Posts: 10,599

Re: calculate across hourly data

[ Edited ]
Posted in reply to tobyfarms

hours without an index (as you used it on the right side of the assignment) is invalid.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Solution
‎10-03-2017 08:04 AM
Trusted Advisor
Posts: 1,399

Re: calculate across hourly data

Posted in reply to tobyfarms

I repeat, your problem is in the NUMERATOR of hours/11065865311.   You need something like hours{I}/11065865311

Contributor
Posts: 56

Re: calculate across hourly data

Thank you @mkeintz and @KurtBremser.

After your initial reply, I did change the numerator to show the index.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 178 views
  • 4 likes
  • 3 in conversation