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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arrays 1

Status
Not open for further replies.

SPhill

Programmer
Sep 17, 2003
32
GB
Hello, I have some data in held in an array which I've managed to extract and it looks like this:-
Code:
Obs inrref covref f1    f2    f3   unitt1 unitt2 unitt3
1   1	   1	  628	.     .     725    0      0
2   2	   1	  .	629   .	    0      565    0
3   3       1      .	.     312    0	   0	  18


I've had a request to hold the data out like this, i.e. stack all my f(i) and unitt(i) into two columns.
Code:
inrref	covref  f's	 unitts
1	     1	   628	    725
2	     1	   629	    565
3	     1	   312	     18
Anyone know how to do this?

Thanks

SP
 
If that is as many variables as you've got, you should be able to just use a datastep to fix that up:-
Code:
data test;
  set inpt1;
       if f1 ne . then fs = f1;
  else if f2 ne . then fs = f2;
  else if f3 ne . then fs = f3;
  
       if unit1 ne . then units = units1;
  else if unit2 ne . then units = units2;
  else if unit3 ne . then units = units3;
run;
If there are alot more possibilities, then you probably want to do a loop of some kind to fix them up.
Code:
  do i=1 to 3;
     if f[i] ne . then fs = f[i];
     if unit[i] ne 0 then units = unit[i];
  end;
Alternatively :-
Code:
  fs = f[inref]
  units = unit[inref]

You basically have 2 sources of the array index, so it's all a matter of which is more reliable/preferably to use, the INREF variable, or the index of the array element of the array that has a value. All 3 of the aboe should give you the same results for the data you've shown above. (I've not tested it though).
 
I've got quite a few variables, the array holds units and fund values for 50 versions, not to mention key variables. I've quickly tested your second suggestion and it seems to work fine, thanks very much.

SP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top