Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

colon modifier (:) in array value and underscore(_in) in array variable name

Status
Not open for further replies.

estersita

Technical User
Aug 5, 2004
50
0
0
US
I am trying to understand the folowing piece of code:

data long (keep=icd9 icd10);
set cwalk_wide;
array _in(*) $ icd10:;
i=1;
do while (i le dim(_in));
if not missing(_in{i}) then do;
icd10=_in(i);
output;
i+1;
end;
else i=dim(_in)+1;
end;
run;

Could you please help me to understand what the above code does (particularly colon:)) and _in?
 
_in(*) is the name of the Array with the '*' as the number of vars in the Array. Using the asterisk allows the user to add vars to the Array dynamically. This way the programmer doesnt have to limit the Array width to a specific number of vars.

Ex.
Code:
Array _in(4) x1 x2 x3 x4;
In the above Array there are exactly 4 vars. In any loop that you set, you would need to set the max counter to 4.

Ex.
Code:
do i=1 to 4;
   your SAS code;
end;

You can also have an array automatically grab all vars of the same type.
Ex.
Code:
Array myTest(*) _character_;
This creates an Array myTest with all the Char variables in the dataset.
If we were to loop through the above array how would we know when to stop the loop? So we use the DIM() function.
ex.
Code:
do i=1 to dim(myTest);
  your SAS code;
end;
As for the second part of the question ':' the colon is used to let SAS know the boundaries of the Array. Most of the time its never used and only in cases that have multi-dimension arrays.



I hope that this helps.

Klaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top