BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tobyfarms
Fluorite | Level 6

 

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;

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

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

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

8 REPLIES 8
mkeintz
PROC Star

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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
tobyfarms
Fluorite | Level 6

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):(Column).

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

 

tobyfarms
Fluorite | Level 6

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.

 

mkeintz
PROC Star

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

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
tobyfarms
Fluorite | Level 6

Thank you @mkeintz and @Kurt_Bremser.

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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