Create a variable

Reply
Occasional Contributor
Posts: 9

Create a variable

I have datafile CAT:

... A

    1

    8

   23

 

A is a column in the datafile. I want to create a variable independent from the dataset (like an object or something else) maxA = the maximum of the all values in column A--so that I can refer to it later.

 

I need to define the demension of my array. Right now maximum of A is 23 so I have:

...

array expo {23} expo1-expo23;

do i = 1 to 23;

...

 

I want to use maxA to make the code 'smarter', like:

...

array expo {maxA } expo1-expomaxA(? I don't know how this would work) ;

do i = 1 to maxA ;

...

 


Now I don't know how to create maxA in a seperate object yet. Thank you very much!

 

Super User
Posts: 19,090

Re: Create a variable

[ Edited ]

You can use macro variables to do this.

 

proc sql noprint;
select max(A) into :MaxA TRIMMED
from CAT;
quit;

Then you can use it as desired:

 

array expo(23) expo1-expo&maxA;

 

Occasional Contributor
Posts: 9

Re: Create a variable

Hi,

 

I wrote my code as:

proc sql noprint;

select max(exposure) into: max_exposure TRIMMED

from mylib.exposure;

quit;

Data Mylib.Matrix;

set mylib.Exposure;

array expo_dur {max_exposure} expo_dur1-expo_dur&max_exposure;

do i=1 to max_exposure;

if exposure < i then expo_dur[i] = exposure - i + 1;

else expo_dur[i] = 1;

if expo_dur[i]<0 then expo_dur[i]=0;

end;

drop i;

Run;

 

However, for the mylib.matrix, I have err message:

ERROR: Too many variables defined for the dimension(s) specified for the array expo_dur.

ERROR 22-322: Syntax error, expecting one of the following: an integer constant, *.

ERROR 202-322: The option or parameter is not recognized and will be ignored.

Thanks!

 

Super User
Posts: 19,090

Re: Create a variable

You forgot the & before the max_ exposure variable in a few places. 

 

 

Ask a Question
Discussion stats
  • 3 replies
  • 355 views
  • 0 likes
  • 2 in conversation