I have two questions regarding Do Loops in SAS.
Say that I have three datasets:
(1) one dataset, called last
with one observation called last_observation
:
last_observation
150
(2) a second dataset with two columns of observations:
Time ID
34200 1
34201 2
34210 3
34213 4
. .
. .
. .
36000 150
Notice that my time increments increases randomly and has 925 observations. The same number found in my 1X1 dataset (1).
(3) A third dataset have
with two columns of observations:
Purchases_unit Time
1000 34200
2000 34210
1243 34211
3040 34300
. .
. .
1000 36000
What I want to do is the following:
data _null_;
set last;
where last=last;
call symput('last_obs',last);run;
%Do i=1 to &'last_obs'; *Hence a loop for 1 to 150 IDs
data want_&i;
set have;
if time<time(i) then delete;
run;
%end;
%mend;
The time(i)
refers to the time column in the second dataset and the (i) is the cell subscript of the time column. So my two questions are:
(1) Will this work?: %Do i=1 to &'last_obs';
if I use the symput
function?
(2) How can I implement the time(i)
index?
I would use a hash object to look up the value you want.
In the first observation, you look up the value from the look up table. Retain that value and use a subsetting if statement.