BookmarkSubscribeRSS Feed
dlazer1
Calcite | Level 5

Hi,

 

I am trying to calculate the firm age based on FISCAL_YEAR_END_OP. I am trying to index the file in order to calculate from the first to late date of the opinion in my dataset. I am not able to output an age based on the code below.

 

Any help would be greatly appreciated!

 

 

proc sort data=opinion;
by COMPANY_FKEY FISCAL_YEAR_END_OP;
run;


data age;
retain index;
set opinion;
if index=. then index=0;
if COMPANY_FKEY = lag(COMPANY_FKEY) then index=index;
else index=index+1;
run;

 

data age;
set age;
by index;
if first.index then output age;
run;

 

 

3 REPLIES 3
PaigeMiller
Diamond | Level 26
proc sort data=opinion;
    by company_fkey fiscal_year_end_op;
run;
data age;
    set opinion;
    lag_company_fkey=lag(company_fkey);
    if company_fkey^=lag_company_fkey then index+1;
run ;
    

I'm not really understanding the point of your last data step. 

--
Paige Miller
mkeintz
PROC Star

Would you please show a sample of how your starting data looks?  And how you want the result to look like?

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ballardw
Super User

Show some example data. Is your FISCAL_YEAR_END_OP a SAS date value, a numeric that represents a year, something else?

 

I doubt if your "index" is at all needed.

 

If your FISCAL_YEAR_END_OP is a year value such as 1994 then this might be as simple as:

 

Proc means data=opinion range; (or since you are counting with your "index" use N instead of range to get number of records for each company_fkey)

   class COMPANY_FKEY

   var FISCAL_YEAR_END_OP;

run;

 

but without knowing what kind of values it is pretty hard to tell whether the calculation you are using is appropriate or not.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

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
  • 3 replies
  • 3676 views
  • 0 likes
  • 4 in conversation