DATA Step, Macro, Functions and more

how to create dummy variable from the variable that has a lot different values

Reply
Contributor
Posts: 66

how to create dummy variable from the variable that has a lot different values

Hi,

 

I have a variable that consists information about diagnosis (6496 different diagnosis). For each diagnosis i want to create a dummy variable and i used this code:

DATA b2;
  set b;
 
  ARRAY dummys {*} 3.  diag1_1 - diag1_6496;
 
  DO i=1 TO 6496;			      
    dummys(i) = 0;
  END;
  dummys( diag1  ) = 1;		
 
RUN;

However, I get this error message:

 

Array subscript out of range at line 2087 column 1.

 

Can anyone tel me what is wrong with code?

 

thank you

Super User
Posts: 10,534

Re: how to create dummy variable from the variable that has a lot different values

With such errors, you get a listing of all variables and their values in the log. Look for the value of diag1. It might be zero or missing.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
PROC Star
Posts: 274

Re: how to create dummy variable from the variable that has a lot different values

Obviously, the value of the DIAG1 variable is not always between 1 and 6496. Is it missing or 0 in some observations? What does the log say about the value of DIAG1 when the error occurs?

Super User
Posts: 10,534

Re: how to create dummy variable from the variable that has a lot different values

Still better: run a proc freq on diag1 and inspect the result.

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

Re: how to create dummy variable from the variable that has a lot different values

Posted in reply to KurtBremser

Thanks,

There is no 0 or missing values; however, I found what was wrong with code (my values were letters not numbers) and I made it work

Super User
Super User
Posts: 9,813

Re: how to create dummy variable from the variable that has a lot different values

I would question why you want to do this.  Just take a simple example of having two records:

DIAG

34

26

 

This is two datapoints of information.  If you transpose that into your structure, you would have 6496 datapoints of information.  This is just a simple example of where your intended data structure is very verbose in terms of storage, but you will also find your coding is far harder as well.

 

Super User
Posts: 10,848

Re: how to create dummy variable from the variable that has a lot different values

data have;
set sashelp.class;
dummy=1;
run;
proc logistic data=have outdesign=want outdesignonly;
class name/param=glm;
model dummy=name;
run;

proc print data=want(drop=dummy intercept) noobs;run;
Ask a Question
Discussion stats
  • 6 replies
  • 95 views
  • 0 likes
  • 5 in conversation