BookmarkSubscribeRSS Feed
yjalilik
Calcite | Level 5

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.

 

 

 

1 REPLY 1
slacey
Obsidian | Level 7

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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 688 views
  • 3 likes
  • 2 in conversation