Help using Base SAS procedures

locating the time with a specific condition in time series

Reply
Occasional Learner
Posts: 1

locating the time with a specific condition in time series

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.

 

 

 

Occasional Contributor
Posts: 9

Re: locating the time with a specific condition in time series

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;
Ask a Question
Discussion stats
  • 1 reply
  • 223 views
  • 3 likes
  • 2 in conversation