View previous topic :: View next topic
|
Author |
Message |
ganeshcet
New User
Joined: 25 Jan 2007 Posts: 11 Location: New York
|
|
|
|
Hi
i have question on sas.in sas program currently i am using array
array branch(100) _temporary_ ;
then later
branch(i) = a+b;
where 100 is the number if records in the input file .i add a+b for all branches. (just looping it) .Now i want to capture the condition when number of records is more than 100. how can i know the count first and set it ? please help . |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
You want to know the number of branches before you build your array ? |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
For a small-ish file:
1. DATA step #1 reads the file, counting records, and at end sets the value of a macro variable to this number
2. DATA step #2 can now do better than what you wanted. It can size the array using the macro variable, thereby effectively dynamically allocating the array to just the size you want
3. DATA step #2 then re-reads the file, knowing that the array is sized correctly |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
If the input data is already in SAS format you could just use the NOBS keyword to get the number of observations in the dataset.
SET &FILEIN (OBS=1) NOBS=NNN; |
|
Back to top |
|
|
ganeshcet
New User
Joined: 25 Jan 2007 Posts: 11 Location: New York
|
|
|
|
Hi
thanks for the help.
here is the code for the macro variable.
DATA _NULL_;
INFILE inputfileddname END=EOF;
INPUT;
IF EOF THEN
CALL SYMPUT('X',_N_);
RUN;
DATA _NULL_;
array arrayvariable(&x) _temporary_; |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
Thanks for posting your resolution. |
|
Back to top |
|
|
|