BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AbuChowdhury
Fluorite | Level 6

Thanks. I will try the code and let you know. I did not read the documentation at this moment. Will you please send me the link?

data_null__
Jade | Level 19
I like this version a bit better.

data difasset2;
   set asset;
   by company_id;
   array _v
  •   ca   cl   stdebt;
  •    array _d[3,3] dca1 dcl1 dstdept1 dca2 dcl2 dstdept2 dca3 dcl3 dstdept3;
       do i = 1 to dim(_v);
          _d[1,i] = dif1(_v);
          _d[2,i] = dif2(_v);
          _d[3,i] = dif3(_v);
          end;
      
    if first.company_id then c=0;
       c +
    1;
      
    do i = c to dim(_v);
          do j = 1 to dim(_v);
             call missing(of _d[i,j]);
             end;
         
    end;
      
    drop i c j;
       run;
    AbuChowdhury
    Fluorite | Level 6

    Hi again, I need to calculate ca at time t+1 as well. So, ca values at t-1, t and t+1.

    data_null__
    Jade | Level 19

    I should have guessed. :smileyplain:  I should have asked before now. Do you have SAS/ETS software?  Type in PROC EXPAND; RUN; and see what your messages are.  If that works consult the documentation.  It does lags leads and a lot more. 

    art297
    Opal | Level 21

    This sure sounds like a FIFO problem. What do you need to do with the lagged data once you get them?

    The following keeps the current and up to the last three values for each variable and then calculates the average of the up to 4 values:

    data want (drop=counter);

      set have;

      by companyISIN notsorted;

      retain counter .;

      array ca_stack {0:3};

      array cl_stack {0:3};

      array stdebt_stack {0:3};

      retain ca_stack cl_stack stdebt_stack;

      if first.companyISIN then do;

        call missing(of ca_stack{*});

        call missing(of cl_stack{*});

        call missing(of stdebt_stack{*});

        counter=0;

      end;

      counter+1;

      ca_stack{mod(counter,4)} = ca;

      cl_stack{mod(counter,4)} = cl;

      stdebt_stack{mod(counter,4)} = stdebt;

      if year not in (2003,2013) then do;

        ca_avg = mean(of ca_stack{*});

        cl_avg = mean(of cl_stack{*});

        stdebt_avg = mean(of stdebt_stack{*});

        output;

      end;

    run;

    sas-innovate-2024.png

    Don't miss out on SAS Innovate - Register now for the FREE Livestream!

    Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

     

    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
    • 19 replies
    • 1647 views
    • 6 likes
    • 5 in conversation