Hi everyone, I am getting an error the following error and cannot figure out why?
Thanks in advanced!
ERROR: Alphabetic prefixes for enumerated variables (Jan_2018-Dec_2019) are different.
data bls.BLS_PPI3;
set bls.BLS_PPI2;
keep Series_id;
array Growth {*} Jan_2018 - Dec_2019;
format Growth_: percent10.1;
keep Growth_:;
array source {*} Jan_2018 - Dec_2019;
do _i=2 to dim(source);
Growth[_i-1]=((source[_i-1]/source[_i])-1);
end;
drop _i;
run;
Hi,
Try Jan_2018 -- Dec_2019 if all these variables are in bls.BLS_PPI2
hth
Thien
Hi Thien,
I keep getting the same error:
10403 data bls.BLS_PPI3;
10404 set bls.BLS_PPI2;
10405 keep Series_id;
10406
10407
10408 array Growth {*} Jan_2018 -- Dec_2019;
ERROR: Variable Jan_2018 cannot be found on the list of previously defined variables.
WARNING: Defining an array with zero elements.
10409 format Growth_: percent10.1;
10410 keep Growth_:;
10411
10412 array source {*} Jan_2018 -- Dec_2019;
ERROR: Variable Jan_2018 cannot be found on the list of previously defined variables.
WARNING: Defining an array with zero elements.
10413
10414 do _i=2 to dim(source);
10415 Growth[_i-1]=((source[_i-1]/source[_i])-1);
10416 end;
10417
10418 drop _i;
10419 run;
WARNING: The variable Growth_: in the DROP, KEEP, or RENAME list has never been referenced.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set BLS.BLS_PPI3 may be incomplete. When this step was stopped there were 0
observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.11 seconds
cpu time 0.04 seconds
@Afor910327 wrote:
Hi Thien,
I keep getting the same error:
10412 array source {*} Jan_2018 -- Dec_2019; ERROR: Variable Jan_2018 cannot be found on the list of previously defined variables.
This variable is not in your data set. Check your data set.
Hi Afor,
When you specify array Growth {*} Jan_2018 -- Dec_2019;
to SAS, you mean all the variables in the dictionary of table bls.BLS_PPI2 starting from Jan_2018 to Dec_2019
Example :
data foobar;
JAN_2018= 201801; foo=1; bar= 2; Dec_2019= 201912;
run;
data _null_;
set foobar;
array Growth {*} Jan_2018 -- Dec_2019;
do i=1 to dim(Growth);
put i= growth(i)=;
end;
run;
Am i correct if I say that an equivalent of your code without array would be something like this:
data BLS_PPI3;
set bls.BLS_PPI2;
format Growth_01-Growth_24 percent10.1;
keep Series_id Growth_:;
Growth_02= (FEB_2018/JAN_2018)-1;
Growth_03= (MAR_2018/FEB_2018)-1;
...
Growth_24= (DEC_2019/NOV_2019)-1;
run;
If yes, variables JAN_2018 FEB_2018 etc DEC_2019 should be in your source table.
hth
Thien
@tlt wrote:
Try Jan_2018 -- Dec_2019 if all these variables are in bls.BLS_PPI2
Yes, they have to be in the data set and in the proper calendar month sequence, otherwise I don't think the array will do what the user wants it to do.
I did all that Paige, and still does not come right. I found out though that the variable name had two under score __ instead of one, so I changed that. Nevertheless, I keep getting the same error:
34
35 data bls.BLS_PPI3;
36 set bls.BLS_PPI2;
37 keep Series_id;
38
39
40 array Growth {*} Jan__2018-Dec__2019;
ERROR: Alphabetic prefixes for enumerated variables (Jan__2018-Dec__2019) are different.
WARNING: Defining an array with zero elements.
41 format Growth_: percent10.1;
42 keep Growth_:;
43
44 array source {*} Jan__2018-Dec__2019;
ERROR: Alphabetic prefixes for enumerated variables (Jan__2018-Dec__2019) are different.
WARNING: Defining an array with zero elements.
45
46 do _i=2 to dim(source);
47 Growth[_i-1]=((source[_i-1]/source[_i])-1);
48 end;
49
50 drop _i;
51 run;
WARNING: The variable Growth_: in the DROP, KEEP, or RENAME list has never been referenced.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set BLS.BLS_PPI3 may be incomplete. When this step was stopped there were 0
observations and 1 variables.
WARNING: Data set BLS.BLS_PPI3 was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.08 seconds
cpu time 0.04 seconds
Hi:
I am unclear on 2 things:
1) Why do you show the SAME variables for both the GROWTH array and the SOURCE array??? That doesn't make sense to me:
2) I believe the "double dash" method will work. Where you are getting errors, the ARRAY statement still shows just a single dash in the ARRAY statement. Here's a revised example with a simplified calculation and using just 3 months and showing the difference between the single dash and the double dash in the ARRAY definition:
An "enumerated" variable is like VAR1, VAR2, VAR3, VAR4, VAR5. In that case, when you have VAR1-VAR5 in the ARRAY statement, the "enumerated" variable has the SAME alphabetic prefix ("VAR") and the number at the end is different. The single dash implies to SAS that your variable list here: VAR1-VAR5 is referring to the whole list of numbered variables. But your array members do not have a common alphabetic prefix with a changing number at the end of the variable name. The double dash will tell SAS to build a list from the PDV of the variables (any variables) that are organized between the starting variable and the ending variable in your list. This may or may not be what you want, depending on how the items are stored in the PDV.
Cynthia
Thank you so much Cynthia, the problem now is that I cannot get the growth rates, but everything seems to be better than before:
NOTE: There were 26 observations read from the data set BLS.BLS_PPI3.
NOTE: PROCEDURE PRINT used (Total process time):
real time 22.25 seconds
cpu time 1.32 seconds
282 data bls.BLS_PPI3;
283 set bls.BLS_PPI2;
284 keep Series_id;
285
286
287 array Growth {*} Jan_2018 -- Dec_2019;
288 format Growth_: percent10.1;
289 keep Growth_:;
290
291 array source {*} Jan_2018 -- Dec_2019;
292 do _i= 2 to dim(source);
293 Growth[_i-1]=((source[_i-1]/source[_i])-1);
294 end;
295
296 drop _i;
297 run;
WARNING: The variable Growth_: in the DROP, KEEP, or RENAME list has never been referenced.
NOTE: There were 26 observations read from the data set BLS.BLS_PPI2.
NOTE: The data set BLS.BLS_PPI3 has 26 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.12 seconds
cpu time 0.04 seconds
298
299
300 proc print data = bls.BLS_PPI3;
@Afor910327 wrote:
Thank you so much Cynthia, the problem now is that I cannot get the growth rates, but everything seems to be better than before:
288 format Growth_: percent10.1; 289 keep Growth_:;
The code above is not referencing the array. It creates a new variable Growth_. Which is never referenced anywhere else in your code. So you get the "never been referenced" warning. If you want to assign a format to the variables in an array then you list the variables, not the array name.
The Purple code is using another named array with the same variable. If you need to reference the same variables then use the same array. Mixing arrays containing the same variables is a path to madness when trying to debug what is going on.
I have to say I am not sure how that calculates growth rate. I would tend to think you would want something like (current value -previous value) / previous value.
Hi:
The issue is that Growth is the name of the array. It does NOT belong in the KEEP statement. The variables are named Jan__2018, Feb__2018, Mar__2018, etc. Growth is just a convenient reference for the ARRAY.
Basically, an ARRAY statement is a way to reference a group of variables. I could have these variables: var1, var2, var3, var4 listed as members of an array. OR, I could have these variables -- differently named: fred, ethel, lucy, ricky listed as members of an array.
The ARRAY name that you use is only available INSIDE the DATA step for referencing. The ARRAY name does NOT exist as a variable name. Therefore, it cannot be used in a drop or keep statement.
Here are some simple examples of using an ARRAY name with differently named variables and same named variables:
1) Declare an array, but do NOT use it:
2) Declare an array and use it:
Note in the above example that I can use the variable names in the KEEP, but CANNOT use the ARRAY name in the KEEP.
3) Declare an array and use same prefix name for the numbered variables:
I don't have any DO loops in my program. I am just showing that the ARRAY name in this example (TVSHOW) is being used to declare an array "reference", where 4 actual data set variables are being declared as array members. The array name is NOT a permanent data construct. The array name is never written to the output data set. The array name is NOT a variable name.
Hope this helps,
Cynthia
ps. I find this paper about using ARRAYS to be very useful: https://support.sas.com/rnd/papers/sgf07/arrays1780.pdf
Hi:
Here's one last example that uses both an ARRAY and a DO loop in the program:
Notice that COST1-COST3 and PRICE1-PRICE3 are available for each PARTNUM. I need to calculate some new variables called PROF1-PROF3. The calculation will be:
PROF variable value = PRICE variable value - COST variable value;
But, if I declare a "MAKECOST" array to have COST1-COST3 as members; and I declare a "SELLFOR" array to have PRICE1-PRICE3 as members, then I can create 3 new variables, PROF1-PROF3 as shown below:
The BALANCE array is declared to have PROF1-PROF3 as members. One of the neat things about ARRAYs in SAS is that if the member names do not exist, SAS will create them in the Program Data Vector (PDV). So, PROF1-PROF3 are created inside the DO loop using the ARRAY references to point to each variable. But the variable names in the output data set WIDGETS are PARTNUM, COST1-COST3, PRICE1-PRICE3 and PROF1-PROF3.
However, if I do NOT list any variables on the ARRAY statement, as shown in the program below (using SAME data as previous program):
then SAS will make me 3 numbered variables named BALANCE1, BALANCE2 and BALANCE3.
Hope this helps,
Cynthia
@Afor910327 wrote:
I did all that Paige, and still does not come right. I found out though that the variable name had two under score __ instead of one, so I changed that. Nevertheless, I keep getting the same error:
34 35 data bls.BLS_PPI3; 36 set bls.BLS_PPI2; 37 keep Series_id; 38 39 40 array Growth {*} Jan__2018-Dec__2019; ERROR: Alphabetic prefixes for enumerated variables (Jan__2018-Dec__2019) are different.
You need
Jan__2018--Dec__2019
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.