You can use PROC MEANS with option: max = maxATQ and
CLASS company ID;
VAR ATq;
WHERE datadate between <date created> and <current date>;
Thank you, I tried but it didn't work
My code is:
proc means data=practice;
max(atq)= max_atq;
class GVKEY;
var atq;
where datadate between <date created> and <current date>;
run;
I dont understand the part <date created> and <current date>. What am I supposed to put into <date created> and <current date>? Because each company has different beginning date. Company 1 data begins at 31/3/1983, company 2 begins at 31/3/1982
Assuming company created date is the lowest value of datadate and current date is the latest one - then you can
just ignore and cancel the where clause.
Did the code worked after removing the where statement ?
if negative - explain what happend and post the log.
It still doesnt work when I remove the where statement
The log file below:
data practice;
set 'c:\mysaslib\firms.sas7bdat';
NOTE: There were 1522473 observations read from the data set c:\mysaslib\firms.sas7bdat.
NOTE: The data set WORK.PRACTICE has 1522473 observations and 25 variables.
NOTE: DATA statement used (Total process time):
real time 0.35 seconds
cpu time 0.35 seconds
138 proc means data=practice;
139 max(atq)=max_atq;
---
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
140 class GVKEY;
141 var atq;
142 run;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
Try next code with the right syntax:
proc means data=practice ;
output out=want max(atq)=max_atq;
class GVKEY;
var atq;
run;
Hi. It works but it produces the maximum value of each company for the entire date range, which is not what I need to do
So the problem is: for each company i:
at t=1: I need to find the maximum value of ATQ from t=0 to t=1
at t=2: Max ATQ from t=0 to t=2
at t=3: Max ATQ from t=0 to t=3
and so on .....
at t=T: Max ATQ from t=0 to t=T
So basically the date range (to find max value) expands when time progress. And I need to find different maximum values of ATQ corresponding with different time range (0 to 1, 0 to 2, 0 to 3, ...... , 0 to T)
I think I need to do some kind of loop?. But I can not find any information on how to do it
What do you mean by t= ?
Is it - first year, first 2 years, first 3 years etc ?
If positive then the use of a data step will be more usefull then proc means:
proc sort data=practice; by GVKEY datadate; run;
data temp;
year = year(datadate);
run;
data want;
set temp;
by gvkey year;
retain maxATQ;
if first.gvkey then maxATQ = ATQ;
maxATQ = max(maxATQ, ATQ);
if last.year then output;
run;
Thanks Shmuel,
absolutely helped me with my problem of continuous updating maximums over time.
Wes
you might adapt a solution I offered earlier https://communities.sas.com/t5/General-SAS-Programming/Estimate-standard-deviation-quarter-by-quarte...
That delivered progressively, the STD() for a number stream within each company, over time
Looks like your task is quite similar
It's a little puzzling what you are looking for, since you don't actually illustrate what the outcome should be. You describe the problem in terms of years. But the date values you use to illustrate are quarters.
Since your data set is in order by GVKEY DATADATE, here is a program that may help.
data want;
set have;
by gvkey;
if first.gvkey then max_atq = atq;
else max_atq = max(max_atq, atq);
retain max_atq;
run;
Note that you can have many observations per DATADATE. But the MAX_ATQ value is the max found so far. Therefore, it can be different for two observations having the same DATADATE.
This program will move you in the right direction. To make the requirements clearer, you will need to provide easier to read data, and a sample of what you picture the result to be (especially when you have two identical DATADATE values for the same GVKEY). Then you can get a better suggested solution.
Hi astounding and shmuel. Your code works.
But Now I have to calculate standard deviation of variable X from quarter I/1983 to quarter II/1983, and then quarter I/1983 to quarter III/1983, and so on.....
It just like before:
at t=1, I need to find standard deviation of X from t=0 to t=1
at t=2, std of X from t=0 to t=2
and so on,
Do you have any idea how to do this? Because the previous code could not applied in this case
I just posted a sample of my dataset. So could anyone help me please?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: