Esteemed Advisers.
I suspect there is a fairly straightforward solution for this situation. But I've not encountered it before so I'm looking for your advice.
In the code below, in the datastep for generating dataset Qc_OUT, the goal is to populate variables station1 and station2 with all possible combinations of non-missing values of STA1 through STA10 as read from dataset RANDOM_METEORS. For each record of RANDOM_METEORS, I want to populate the array STATION[] with the non-missing values of STA1 through STA10. I currently have to identify by inspection the maximum value of STATIONCOUNT among all the records in order to hard code the dimension of array STATION and to specify the limits of the two loops thtat follow the ARRAY statement. I'm asking your help to find a way to use the value of STATIONCOUNT to properly form the ARRAY statement and the loops. I know I can substitute STATIONCOUNT for the array dimension and use it for loop control but I don't know how to code the initial-value list to encompass the next dimension of array STATION as the datastep moves to the next record.
BTW, the data step for initial data was created using the macro %data2datastep. I recently discovered this, and after figuring out how to use it (I thought the documentation might be a little weak for some), find it to be immensely helpful in preparing code in support of submitting questions to this forum.
Many thanks in advance for any advice you can provide,
Gene
data WORK.MERGED_MAXMIN_TXTYTZ;
infile datalines dsd truncover;
input concat:$70. _FREQ_:32. txmax:32. tymax:32. tzmax:32. txmin:32. tymin:32. tzmin:32. stationcount:32.;
datalines4;
US000S/US000V,79,30,-90,120,-200,-280,70,2
US000S/US000V/US001E,832,20,-110,120,-200,-270,70,3
US000S/US000V/US001E/US001Q,337,-10,-130,120,-200,-310,70,4
US000S/US000V/US001Q,5,-10,-280,120,-20,-300,80,3
US000S/US001E,37,-30,-120,120,-220,-350,70,2
US000S/US001E/US001Q,2115,-40,-120,120,-270,-360,70,3
US000S/US001Q,773,-210,-140,120,-390,-340,70,2
US000U/US000V,20,50,20,120,30,-40,90,2
US000V/US001E,514,40,-100,120,-170,-220,70,2
US000V/US001R,101,-110,0,120,-160,-50,70,2
US001E/US001Q,343,-90,-330,120,-270,-400,70,2
;;;;
run;
/* SAS macro from Wicklin for generating Random Numbers between a Min and Max */
%macro RandBetween(min, max);
(&min + floor((1+&max-&min)*rand("uniform")))
%mend;
data Random_Meteors (drop= r _freq_ temp);
set MERGED_MAXMIN_TXTYTZ;
by concat;
call streaminit(123456);
if missing(concat) then delete;
gridpoints=_freq_;
if gridpoints=1 then delete;
meteorct=0;
do while (meteorct<1);
TX_Start = %RandBetween(txmin, txmax);
TY_Start = %RandBetween(tymin, tymax);
TZ_Start = %RandBetween(90, 120);
TX_End = %RandBetween(txmin, txmax);
TY_End = %RandBetween(tymin, tymax);
TZ_End = %RandBetween(70, 100);
if tz_end > Tz_start then do;
temp=tz_end;
tz_end=tz_start;
tz_start=temp;
end;
TrackLength=sqrt((TX_Start-TX_End)**2+(TY_Start-TY_End)**2+(TZ_Start-TZ_End)**2);
r=divide((tz_start-tz_end),tracklength);
Entryangle=arsin(r)*180/constant('pi');
/* if tracklength<10 or EntryAngle<15, generate another meteor*/
if tracklength<10 or entryangle<15 then continue;
meteorct+1;
/*Separate concat for Qc analysis*/
sta1=scan(concat,1,'/');
sta2=scan(concat,2,'/');
sta3=scan(concat,3,'/');
sta4=scan(concat,4,'/');
sta5=scan(concat,5,'/');
sta6=scan(concat,6,'/');
sta7=scan(concat,7,'/');
sta8=scan(concat,8,'/');
sta9=scan(concat,9,'/');
sta10=scan(concat,10,'/');
output;
end;
run;
/*Calculate Qc for each Random Meteor in FoV of all station pairs*/
Data QC_out (keep=stationcount concat station1 station2);
set random_meteors;
/* QUESTION: How to define array STATION[] to process all possible pairs of up to STA1-STA10 in RANDOM_METEORS by using
STATIONCOUNT for each record in RANDOM_METEORS as the dimension for STATION[]?
Don't know how to declare variable values STA1-STA10 for array STATION
to be consistent with variable array dimension that would come from STATIONCOUNT.
Currently hard-coded with maximum of STATIIONCOUNT found by inspection*/
array station[4] $ STA1-STA4;
do i=1 to 3;
do j=i+1 to 4;
station1= station{i};
station2= station{j};
if station2 eq '' then continue;
output;
end;
end;
run;
... View more