Help using Base SAS procedures

Error: Variable CC has already been defined..CC is unknown or cannot be accessed

Reply
Contributor
Posts: 21

Error: Variable CC has already been defined..CC is unknown or cannot be accessed

data RESULT;

set ID_CC;

by ID;

retain CC1-CC177;

array CC(177) CC1-CC177;

array DD(177) $ DD1-DD177;

do i=1 to 177;

  percent=CC(i)/CC(_n_);

  DD(i)=cats(CC(i),"(",put(percent, percent8.1),")");

end;

run;

Can anyone let me know what's wrong with the code here? I keep getting messages like

ERROR 124-185: The variable CC has already been defined.

ERROR 68-185: The function CC is unknown, or cannot be accessed.

Super User
Posts: 17,829

Re: Error: Variable CC has already been defined..CC is unknown or cannot be accessed

Do you have a variable named CC in your ID_CC dataset? Also make sure you have only 177 observations in your ID_CC dataset.

It's also easiest if you post the log from your code with the errors.

data RESULT;

set ID_CC;

by ID;

retain CC1-CC177;

array CC_LIST(177) CC1-CC177;

array DD_LIST(177) $ DD1-DD177;

do i=1 to 177;

  percent=CC_LIST(i)/CC_LIST(_n_);

  DD(i)=cats(CC_LIST(i),"(",put(percent, percent8.1),")");

end;

run;

Contributor
Posts: 21

Re: Error: Variable CC has already been defined..CC is unknown or cannot be accessed

Hello Reeza,

Sorry for the confusion. In my ID_CC dataset, I have two variables (ID and CC). The CC can be ranged from 1-177 but the observations are way more than 177 (approximately 80,000)

Super User
Posts: 5,082

Re: Error: Variable CC has already been defined..CC is unknown or cannot be accessed

That should be the answer then.  It's illegal to name an array using the same name as an existing variable.  Just change the array name.

On a similar note, if you name an array using the same name as a function, the function is disabled for the duration of the DATA step.  References to that name always refer to the array for the duration of the DATA step.

Good luck.

Super User
Posts: 6,936

Re: Error: Variable CC has already been defined..CC is unknown or cannot be accessed

First, I suggest to use curly brackets to adress individual array elements; this avoids the confusion with a possible function name.

Second, get a count of the observations in your dataset. Using _N_ as an array index is VERY dangerous.

Third, what in $DEITY's name do you want to achieve?

You could also post the ouput of proc contents run on your ID_CC dataset.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 21

Re: Error: Variable CC has already been defined..CC is unknown or cannot be accessed

These are the exact codes I used. In this case, mhn is id.

data RESULT_PRE;

set MEMBER_CC;

by mhn;

retain CC1-CC177;

array CC_LIST(177) CC1-CC177;

if first.mhn then do i=1 to 177;

   CC_LIST(i)=0;

end;

CC_LIST(CC)=1;

if last.mhn then output;

run;

data RESULT;

set RESULT_PRE;

array CC_LIST(177) CC1-CC177;

array HCC_LIST(177) $ HCC1-HCC177;

do i=1 to 177;

   percent=CC_LIST(i)/CC_LIST(_n_);

   HCC_LIST(i)=cats(CC_LIST(i), "(", put(CC_LIST(i)/CC_LIST(_n_), percent8.1), ")");

end;

run;



The log result is way too big, I'm attaching the key errors below:

NOTE: Division by zero detected at line 22 column 22.

WARNING: Limit set by ERRORS= option reached.  Further errors of this type will not be printed.

ERROR: Array subscript out of range at line 22 column 23.

NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to

      missing values.

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

      30798 at 22:22   30798 at 23:52  



Contributor
Posts: 21

Re: Error: Variable CC has already been defined..CC is unknown or cannot be accessed

I'm trying to accomplish by counting unique cc and put them in matrix form. I would like my result looks like

CC     1                        2            3        .....   177

1     125(100%)          25(20%)

2

3     

...

177

In other words, how many have CC1 also have CC2..CC177 and individual percentage.

Super User
Super User
Posts: 7,401

Re: Error: Variable CC has already been defined..CC is unknown or cannot be accessed

Hi,

Sorry, not totally clear on your logic, so hopefully this helps.  I would first categorise the data, i.e. so you know that an ID has the 1-2 match, then you can simple sum these and transpose the results, something like:

data have;

  length id $2. cc 8;

  input id $ cc;

datalines;

a 1

a 2

a 3

b 1

b 2

c 1

;

run;

proc sql;

  create table INTER as

  select  A.ID,

          strip(put(A.CC,best.))||" to "||strip(put(B.CC,best.)) as RES

  from    WORK.HAVE A

  left join WORK.HAVE B

  on      A.ID=B.ID

  and     (B.CC = A.CC + 1 or (A.CC=1 and B.CC=1));

quit;

proc sql;

  create table INTER2 as

  select  RES,

          count(ID) as NUM

  from    INTER

  group by RES;

quit;

Super User
Posts: 10,500

Re: Error: Variable CC has already been defined..CC is unknown or cannot be accessed

This following code structure is invalid when the number of records exceeds the size of the array declared:

percent=CC_LIST(i)/CC_LIST(_n_);

That is why you get the "array out of bounds". As soon as you get to record 178 and _n_=178 there is no array element 178.

I think you might want to provide example of your input data with maybe 4 instead of 177 values and what you want the output to be.

Super User
Posts: 17,829

Re: Error: Variable CC has already been defined..CC is unknown or cannot be accessed

That shouldn't happen, at worst you may have less than 177 because there wasn't a value present. The table comes from a proc corr output:

The original question was on SO and I suggested Kelly move it here as I think s/he requires more help than possible on SO.

proc - Two Way Transpose SAS Table - Stack Overflow

I am trying to create a two way transposed table. The original table I have looks like

id      cc 1       2 1       5 1       40 2       55 2       2 2       130 2       177 3       20 3       55 3       40 4       30 4       100

I am trying to create a table that looks like

CC        CC1     CC2…  …CC177 1         264     5        0 2         0      132       6 … … 177       2        1      692

In other words, how many id have cc1 also have cc2..cc177..etc

The number under ID is not count; an ID could range from 3 digits to 5 digits ID or with numbers such as 122345ab78

Is it possible to have percentage display next to each other?

  CC CC1 % CC2 %… …CC177 1 264 100% 5 1.9% 0 2 0 132 6 … … 177 2 1 692 

If I want to change the CC1 CC2 to characters, how do I modify the arrays? Eventually, I would like my table looks like

CC Dell Lenovo HP Sony Dell Lenovo HP Sony 

The order of the names must match the CC number I provided above. CC1=Dell CC2=Lenovo, etc. I would also want to add percentage to the matrice. If Dell X Dell = 100 and Dell X Lenovo = 25, then Dell X Lenovo = 25%.

Contributor
Posts: 21

Re: Error: Variable CC has already been defined..CC is unknown or cannot be accessed

Hello everyone,

Thanks for everyone's help. I have posted more detail on my code. The attached link is what I want my tables look like.

Ask a Question
Discussion stats
  • 10 replies
  • 964 views
  • 0 likes
  • 6 in conversation