Hi!
I am running computer simulations and recording the values of a variable over time. I need to find out the when the variable reaches a predefined value for the first time and store it for further analysis. Can this be done in SAS? Also is there a procedure to calculate autocorrelation of a time series for a specific period of time (e.g. t=60 to t=200)?
My data will look like something like this:
time variable
1 10
2 12
3 15
4 35
5 48
6 60
7 87
8 120
and I need to find out at what time variable becomes greater than or equal to 35. The output of the code should be t=4.
Thank you.
For the getting time something like this will work. The idea is we take advantage of the implicit loop in the SAS datastep and once it hits our threshold (here set to 35), it outputs that time value into a macro variable called tval and then stops the datastep.
data ds1;
input time var;
datalines;
1 10
2 12
3 15
4 35
5 48
6 60
7 87
8 120
;
run;
proc sort data=ds1; by time; run;
data _NULL_;
set ds1;
if var >= 35 then do;
call symput("tval",strip(put(time,3.)));
stop;
end;
run;
%put &tval;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.