<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to lag values as many rows as designated, iteratively over all variables? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713258#M220007</link>
    <description>&lt;P&gt;This is not a LAG problem.&amp;nbsp; It's more of a rearrange problem.&amp;nbsp; &amp;nbsp; Although all of your sample data shows values that are carried forward to subsequent observations, I bet you will have some instances that will have to be carried backward &lt;STRIKE&gt;forward&lt;/STRIKE&gt; as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the values are actually consecutive integers as you show, then the program is a straightforward population of a matrix (1 row observation in original, and 1 col per VAR variable in original), followed by retrieval and output of the matrix:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Original;
input ANALYS var1 var2 var3 ;
CARDS;
1 5 3 7
2 . 7 9
3 . 9 10
4 . . .
5 . . .
6 . . .
7 . . .
8 . . .
9 . . .
10 . . .
;;;;

/* Get number of rows and columns needed for the matrix */
data _null_;
  set original nobs=n_analys;
  call symput('n_analysts',cats(n_analys));
  array cusip_ids {*} var: ;
  call symput('n_cusips',cats(dim(cusip_ids)));
  stop;
run;
%put &amp;amp;=n_analysts;
%put &amp;amp;=n_cusips;

data want (drop=col row);
  array anls {&amp;amp;n_analysts} _temporary_;         /* List of ANALYS values */
  array t {&amp;amp;n_analysts,&amp;amp;n_cusips} _temporary_; /*2-way array, i.e. a 2-dim matrix */

  set original end=end_of_first_pass;
  anls{_n_}=analys;
  array _var {&amp;amp;n_cusips} var: ;
  /* From each VAR value, fill a cell in the corresponding row */
  do col=1 to dim(_var);
    if _var{col}^=. then t{_var{col},col}=_var{col};
  end;

  if end_of_first_pass;       /* One the input data is exhausted ... */
  do row=1 to dim(anls);
    analys=anls{row};
    do col=1 to &amp;amp;n_cusips;
      _var{col}=t{row,col};
    end;
    output;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I bet your values of ANALYS are not consecutive integers, right?&amp;nbsp;If not, then the 2-way array will have to be replaced by something like a hash object:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=v rc _:);
  set original end=end_of_first_pass;

  array _anls {&amp;amp;n_analysts} _temporary_ ; /* Temp store for all the ANALYS ids in ORIGINAL order */
  _anls{_n_}=analys;

  array vars  {&amp;amp;n_cusips} var: ;
  array _tmps {&amp;amp;n_cusips} ;               /* Temp Store for the current set of VAR values */

  if _n_=1 then do;  /*H is a lookup table keyed on ANALYS */
    declare hash h (dataset:'original(obs=0)');
      h.definekey('analys');
      h.definedata(all:'Y');
      h.definedone();
  end;

  do v=1 to dim(vars);
    _tmps{v}=vars{v};
  end;
  call missing(of vars{*});

  if h.check(key:analys)^=0 then h.add();   /*If this ANALYS not yet in h then put it in*/

  do v=1 to dim(vars);
    call missing(of vars{*});
    if _tmps{v}=. then continue;
    analys=_tmps{v};
    rc=h.find(key:analys);
    vars{v}=_tmps{v};
    h.replace();
  end;

  if end_of_first_pass then do v=1 to &amp;amp;n_analysts;
    analys=_anls{v};
    h.find();
    output;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In fact is ANALYS even a numeric variable?&amp;nbsp; If not then you will need to change the _ANLS numeric array to a character array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 23 Jan 2021 03:59:19 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2021-01-23T03:59:19Z</dc:date>
    <item>
      <title>How to lag values as many rows as designated, iteratively over all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713179#M219974</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your help in advance!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset of 6,263 obs. and 4,590 variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Each variable has only a few actual observations on top, and remaining observations are all missing.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to lag the values far down to their designated places, and that iteratively over all the variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, this is what my original dataset looks like:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data Original;&lt;BR /&gt;input ANALYS var1 var2 var3 ;&lt;BR /&gt;CARDS;&lt;BR /&gt;1 5 3 7&lt;BR /&gt;2 . 7 9&lt;BR /&gt;3 . 9 10&lt;BR /&gt;4 . . .&lt;BR /&gt;5 . . .&lt;BR /&gt;6 . . .&lt;BR /&gt;7 . . .&lt;BR /&gt;8 . . .&lt;BR /&gt;9 . . .&lt;BR /&gt;10 . . .&lt;BR /&gt;;;;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I want to make my dataset look like the below:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data WANT;&lt;BR /&gt;input ANALYS var1 var2 var3 ;&lt;BR /&gt;CARDS;&lt;BR /&gt;1 . . .&lt;BR /&gt;2 . . .&lt;BR /&gt;3 . 3 .&lt;BR /&gt;4 . . .&lt;BR /&gt;5 5 . .&lt;BR /&gt;6 . . .&lt;BR /&gt;7 . 7 7&lt;BR /&gt;8 . . .&lt;BR /&gt;9 . 9 9&lt;BR /&gt;10 . . 10&lt;BR /&gt;;;;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I really appreciate your help, and life-saving!!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sincerely,&amp;nbsp;&lt;/P&gt;&lt;P&gt;KS -,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2021 18:58:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713179#M219974</guid>
      <dc:creator>KS99</dc:creator>
      <dc:date>2021-01-21T18:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag values as many rows as designated, iteratively over all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713182#M219975</link>
      <description>&lt;P&gt;Lagging 4000 + variables is likely to be fraught with all sorts of issues. If nothing adding tens, if not hundreds of thousands of temporary values to keep track of.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How about: Providing values that are not the actual "rows" that you want to place data on (there are solutions for that sort of data that probably would not work in a generic solution) and provide the rules for how we know that var1 from observation 1 is supposed to get to observation 5. Even with a "lag" approach we need to know all the rules for which variable values go where.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By any chance is the largish number of variables related to different times of data collection or related to the value?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2021 19:08:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713182#M219975</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-21T19:08:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag values as many rows as designated, iteratively over all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713187#M219977</link>
      <description>&lt;P&gt;Thank you for your quick reply!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I forgot to tell you about the rules of placing values.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The very first variable ANALYS is the benchmark, and the values of all other variables are supposed to align with the values of ANALYS. If the value of ANALYS is 9, then all 9's from other variables should line up there in that row..&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is actually WRDS global finance data, the analysts on the row, and company identifier (CUSIP) on the column.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was trying to make a matrix for a network study.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;KS -,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2021 19:24:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713187#M219977</guid>
      <dc:creator>KS99</dc:creator>
      <dc:date>2021-01-21T19:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag values as many rows as designated, iteratively over all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713211#M219985</link>
      <description>From your Original to Want, please explain the logic between ANALYS 4 to 10 and why rows 7, 9 and 10 are filled in but the remainders are not. There's no logic to that that I can see.</description>
      <pubDate>Thu, 21 Jan 2021 20:21:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713211#M219985</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-01-21T20:21:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag values as many rows as designated, iteratively over all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713245#M219998</link>
      <description>&lt;P&gt;Thank you for your reply!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The story about this dataset is that I wanted to transform a panel data of forecasting analysts and their firms into a matrix with a row of analysts and a column of firm identifiers.&amp;nbsp;&lt;/P&gt;&lt;P&gt;From the SAS window, Original looks like this:&lt;/P&gt;&lt;P&gt;(It has 6,263 obs. and 4,589 variables)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="KS99_0-1611268430499.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/53781i15B2F790DB84E2AD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="KS99_0-1611268430499.png" alt="KS99_0-1611268430499.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;After I disperse the values to their appropriate rows for all the variables, I am going to change the missing to 0, the non-missing to 1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks!&amp;nbsp;&lt;/P&gt;&lt;P&gt;KS -,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2021 22:36:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713245#M219998</guid>
      <dc:creator>KS99</dc:creator>
      <dc:date>2021-01-21T22:36:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag values as many rows as designated, iteratively over all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713247#M220000</link>
      <description>I'm sorry but that doesn't answer the questions asked.</description>
      <pubDate>Thu, 21 Jan 2021 22:43:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713247#M220000</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-01-21T22:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag values as many rows as designated, iteratively over all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713251#M220001</link>
      <description>&lt;P&gt;Oh, sorry, maybe I am mistaken..&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why some values are filled, whereas others are missing, is simply by chance (from the database).&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ANALYS 1-10 are analyst ID. Var1-Var3 are stock1, stock2, and stock3.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, the dataset is reporting that stock1 is taken care of by analyst 5, stock2 by analysts 3,7,9, stock3 by analysts 7,9,10.&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want to do is to drag down the values to the right places corresponding to ANALYS.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ANALYS var1 var2 var3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; 9&amp;nbsp; &amp;nbsp; &amp;nbsp; 10&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am I answering you question correctly?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&amp;nbsp;&lt;/P&gt;&lt;P&gt;KS -,&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2021 23:09:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713251#M220001</guid>
      <dc:creator>KS99</dc:creator>
      <dc:date>2021-01-21T23:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag values as many rows as designated, iteratively over all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713258#M220007</link>
      <description>&lt;P&gt;This is not a LAG problem.&amp;nbsp; It's more of a rearrange problem.&amp;nbsp; &amp;nbsp; Although all of your sample data shows values that are carried forward to subsequent observations, I bet you will have some instances that will have to be carried backward &lt;STRIKE&gt;forward&lt;/STRIKE&gt; as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the values are actually consecutive integers as you show, then the program is a straightforward population of a matrix (1 row observation in original, and 1 col per VAR variable in original), followed by retrieval and output of the matrix:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Original;
input ANALYS var1 var2 var3 ;
CARDS;
1 5 3 7
2 . 7 9
3 . 9 10
4 . . .
5 . . .
6 . . .
7 . . .
8 . . .
9 . . .
10 . . .
;;;;

/* Get number of rows and columns needed for the matrix */
data _null_;
  set original nobs=n_analys;
  call symput('n_analysts',cats(n_analys));
  array cusip_ids {*} var: ;
  call symput('n_cusips',cats(dim(cusip_ids)));
  stop;
run;
%put &amp;amp;=n_analysts;
%put &amp;amp;=n_cusips;

data want (drop=col row);
  array anls {&amp;amp;n_analysts} _temporary_;         /* List of ANALYS values */
  array t {&amp;amp;n_analysts,&amp;amp;n_cusips} _temporary_; /*2-way array, i.e. a 2-dim matrix */

  set original end=end_of_first_pass;
  anls{_n_}=analys;
  array _var {&amp;amp;n_cusips} var: ;
  /* From each VAR value, fill a cell in the corresponding row */
  do col=1 to dim(_var);
    if _var{col}^=. then t{_var{col},col}=_var{col};
  end;

  if end_of_first_pass;       /* One the input data is exhausted ... */
  do row=1 to dim(anls);
    analys=anls{row};
    do col=1 to &amp;amp;n_cusips;
      _var{col}=t{row,col};
    end;
    output;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I bet your values of ANALYS are not consecutive integers, right?&amp;nbsp;If not, then the 2-way array will have to be replaced by something like a hash object:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=v rc _:);
  set original end=end_of_first_pass;

  array _anls {&amp;amp;n_analysts} _temporary_ ; /* Temp store for all the ANALYS ids in ORIGINAL order */
  _anls{_n_}=analys;

  array vars  {&amp;amp;n_cusips} var: ;
  array _tmps {&amp;amp;n_cusips} ;               /* Temp Store for the current set of VAR values */

  if _n_=1 then do;  /*H is a lookup table keyed on ANALYS */
    declare hash h (dataset:'original(obs=0)');
      h.definekey('analys');
      h.definedata(all:'Y');
      h.definedone();
  end;

  do v=1 to dim(vars);
    _tmps{v}=vars{v};
  end;
  call missing(of vars{*});

  if h.check(key:analys)^=0 then h.add();   /*If this ANALYS not yet in h then put it in*/

  do v=1 to dim(vars);
    call missing(of vars{*});
    if _tmps{v}=. then continue;
    analys=_tmps{v};
    rc=h.find(key:analys);
    vars{v}=_tmps{v};
    h.replace();
  end;

  if end_of_first_pass then do v=1 to &amp;amp;n_analysts;
    analys=_anls{v};
    h.find();
    output;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In fact is ANALYS even a numeric variable?&amp;nbsp; If not then you will need to change the _ANLS numeric array to a character array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jan 2021 03:59:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713258#M220007</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-01-23T03:59:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag values as many rows as designated, iteratively over all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713275#M220016</link>
      <description>&lt;P&gt;Dear mkeintz,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for your help!&amp;nbsp;I really appreciate it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ran the codes you provided, but there seems to be a small obstacle.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I got the following warning (bold) in the first part of your codes,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;119 data _null_;&lt;BR /&gt;120 set Matrix_2016 nobs=n_analys;&lt;BR /&gt;121 call symput('n_analysts',cats(n_analys));&lt;BR /&gt;122 array cusip_ids {*} var: ;&lt;BR /&gt;&lt;STRONG&gt;WARNING: Defining an array with zero elements.&lt;/STRONG&gt;&lt;BR /&gt;123 call symput('n_cusips',cats(dim(cusip_ids)));&lt;BR /&gt;124 stop;&lt;BR /&gt;125 run;&lt;/P&gt;&lt;P&gt;NOTE: There were 1 observations read from the data set WORK.MATRIX_2016.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.01 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And running the latter part of your codes, I receives the following error message.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ERROR: Invalid dimension specification for array vars. The upper bound of an array dimension is smaller than its&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;corresponding lower bound.&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;ERROR: Too few variables defined for the dimension(s) specified for the array vars.&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;ERROR: Invalid dimension specification for array _tmps. The upper bound of an array dimension is smaller than its&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;corresponding lower bound.&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you help me a little bit more with this? I would greatly appreciate it,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sincerely,&amp;nbsp;&lt;/P&gt;&lt;P&gt;KS -,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2021 03:09:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713275#M220016</guid>
      <dc:creator>KS99</dc:creator>
      <dc:date>2021-01-22T03:09:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag values as many rows as designated, iteratively over all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713290#M220025</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/365070"&gt;@KS99&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear mkeintz,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much for your help!&amp;nbsp;I really appreciate it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I ran the codes you provided, but there seems to be a small obstacle.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I got the following warning (bold) in the first part of your codes,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;119 data _null_;&lt;BR /&gt;120 set Matrix_2016 nobs=n_analys;&lt;BR /&gt;121 call symput('n_analysts',cats(n_analys));&lt;BR /&gt;122 array cusip_ids {*} var: ;&lt;BR /&gt;&lt;STRONG&gt;WARNING: Defining an array with zero elements.&lt;/STRONG&gt;&lt;BR /&gt;123 call symput('n_cusips',cats(dim(cusip_ids)));&lt;BR /&gt;124 stop;&lt;BR /&gt;125 run;&lt;/P&gt;
&lt;P&gt;NOTE: There were 1 observations read from the data set WORK.MATRIX_2016.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.01 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And running the latter part of your codes, I receives the following error message.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;ERROR: Invalid dimension specification for array vars. The upper bound of an array dimension is smaller than its&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;corresponding lower bound.&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;ERROR: Too few variables defined for the dimension(s) specified for the array vars.&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;ERROR: Invalid dimension specification for array _tmps. The upper bound of an array dimension is smaller than its&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;corresponding lower bound.&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you help me a little bit more with this? I would greatly appreciate it,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you !&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sincerely,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;KS -,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You got the warning probably because you didn't provide us the actual names of your cusip variables.&amp;nbsp; You used "VAR1 VAR2 VAR3", so I defined the array CUSIP_IDS as all the variables whose name begins with VAR&amp;nbsp; (see line 122 where I used "var:" ). Apparently you have no variables whose name beging with "VAR", so SAS told you that the array has zero elements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have to provide the ARRAY statement with the list of names that you do want to rearrange.&amp;nbsp; If you're lucky and they all start with the same letters (like CUS...), then you can specify the list&amp;nbsp; as "cus:" - all vars whose name begins with "cus".&amp;nbsp; &amp;nbsp; But there are other ways to generate a list of variables names if this is not the case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For instance, if the first cusip variable name was, say "apple_cusip"&amp;nbsp; and the last was "xerox_cusip", and every variables between them were cusips of interest, you could generate the needed list using a double-dash, as in&amp;nbsp; &lt;EM&gt;&lt;STRONG&gt;array cusip_ids {*} apple_cusip--xerox_cusip;&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp; But this assumes the cusip values are numeric, and cusip id's can have letters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So what are the names, and variable types (character or numeric) of the 4,590 cusip variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2021 05:51:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713290#M220025</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-01-22T05:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag values as many rows as designated, iteratively over all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713318#M220045</link>
      <description>&lt;P&gt;As other responders have pointed out, this is hardly a lagging problem.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are my 2 cents. Feel free to ask &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ANALYS var1 var2 var3 ;
CARDS;
1 5 3 7
2 . 7 9
3 . 9 10
4 . . .
5 . . .
6 . . .
7 . . .
8 . . .
9 . . .
10 . . .
;;;;

data want(drop = k);
   
   if _N_ = 1 then do;

      dcl hash h(multidata : "Y");
      h.definekey('k');
      h.definedata('k', '_i_');
      h.definedone();

      do until (z);
         set have end = z;
         array v var1-var3;
         do over v;
            if v then do;
               k = v;
               h.add();
            end;
         end;
      end;
   end;

   set have;
   call missing(of var:);

   do while (h.do_over(key : _N_) = 0);
      v = k;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ANALYS var1 var2 var3 
1      .    .    . 
2      .    .    . 
3      .    3    . 
4      .    .    . 
5      5    .    . 
6      .    .    . 
7      .    7    7 
8      .    .    . 
9      .    9    9 
10     .    .    10 
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code is reasonably fast for the size of your original data as well:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   do analysis = 1 to 5000;
      array v var1 - var5000;
      do over v;
          v = ifn(rand('uniform') &amp;lt; .2, ceil(rand('uniform') * 5000), .);
      end;
      output;
   end;
run;

data want(drop = k);
   
   if _N_ = 1 then do;
      array v var1-var5000;

      dcl hash h(multidata : "Y");
      h.definekey('k');
      h.definedata('k', '_i_');
      h.definedone();

      do until (z);
         set have end = z;
         do over v;
            if v then do;
               k = v;
               h.add();
            end;
         end;
      end;
   end;

   set have;
   call missing(of var:);

   do while (h.do_over(key : _N_) = 0);
      v = k;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;NOTE: There were 5000 observations read from the data set WORK.HAVE.
NOTE: There were 5000 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 5000 observations and 5001 variables.
NOTE: DATA statement used (Total process time):
      real time           3.03 seconds
      cpu time            3.00 seconds
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2021 10:14:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713318#M220045</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-01-22T10:14:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag values as many rows as designated, iteratively over all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713332#M220052</link>
      <description>&lt;P&gt;Maybe I am head full of SQL .&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ANALYS var1 var2 var3 ;
CARDS;
1 5 3 7
2 . 7 9
3 . 9 10
4 . . .
5 . . .
6 . . .
7 . . .
8 . . .
9 . . .
10 . . .
;;;;
proc sql;
create table want as
select *
from (select analys from have) as a left join
     (select var1 from have) as b   on a.analys=b.var1 left join
	 (select var2 from have) as c   on a.analys=c.var2 left join 
     (select var3 from have) as d   on a.analys=d.var3 ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Jan 2021 12:24:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713332#M220052</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-01-22T12:24:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag values as many rows as designated, iteratively over all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713343#M220060</link>
      <description>&lt;P&gt;Sounds like you want an adjacency matrix.&amp;nbsp; It probably would help to first normalize your data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ANALYS var1 var2 var3 ;
CARDS;
1 5 3 7
2 . 7 9
3 . 9 10
4 . . .
5 . . .
6 . . .
7 . . .
8 . . .
9 . . .
10 . . .
;;;;

proc transpose data=have out=tall;
  by analys;
  var var1-var3 ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then your output looks like a simple report.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=tall;
  column col1 analys,col1=xx ;
  define col1 / group ' ';
  define analys / across ' ';
  define xx / max ' ';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 125px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/53801iEDD62710080D76F6/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2021 13:39:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713343#M220060</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-22T13:39:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag values as many rows as designated, iteratively over all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713453#M220110</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Maybe I am head full of SQL .&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;... 
proc sql;
create table want as
select *
from (select analys from have) as a left join
     (select var1 from have) as b   on a.analys=b.var1 left join
	 (select var2 from have) as c   on a.analys=c.var2 left join 
     (select var3 from have) as d   on a.analys=d.var3 ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Neat, I think the OP has 4,590 variables.&amp;nbsp; That would be a lot of left joins.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2021 19:03:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713453#M220110</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-01-22T19:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag values as many rows as designated, iteratively over all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713491#M220128</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Dear mkeintz,&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Oh, thank you for pointing out what I am missing!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;So, today, I struggled to attach a prefix "Var_" to all the variables, using a set of codes provided by SAS support.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Rename all the variables, adding prefix "Var_" */&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;select cats(name,'=','Var_',name)&lt;BR /&gt;into :list&lt;BR /&gt;separated by ' '&lt;BR /&gt;from dictionary.columns&lt;BR /&gt;where libname = 'WORK' and memname = 'Matrix_2016'; quit;&lt;BR /&gt;proc datasets library = work nolist;&lt;BR /&gt;modify Matrix_2016;&lt;BR /&gt;rename &amp;amp;list; run; quit;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I ended up with another error message like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;156 proc datasets library = work nolist;&lt;BR /&gt;157 modify Matrix_2016;&lt;BR /&gt;&lt;FONT color="#800000"&gt;&lt;EM&gt;WARNING: Apparent symbolic reference LIST not resolved.&lt;/EM&gt;&lt;/FONT&gt;&lt;BR /&gt;158 rename &lt;U&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;&amp;amp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/U&gt;list; run;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I am sorry to take your precious time, but I really appreciate your help!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sincerely,&amp;nbsp;&lt;/P&gt;&lt;P&gt;KS -,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2021 21:36:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713491#M220128</guid>
      <dc:creator>KS99</dc:creator>
      <dc:date>2021-01-22T21:36:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag values as many rows as designated, iteratively over all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713494#M220130</link>
      <description>To answer your quick question:&lt;BR /&gt;The names of the variables look like these:&lt;BR /&gt;&lt;BR /&gt;_00036020 Num 8 BEST.&lt;BR /&gt;_00036110 Num 8 BEST.&lt;BR /&gt;_00037520 Num 8 BEST.&lt;BR /&gt;_00108410 Num 8 BEST.&lt;BR /&gt;_00154710 Num 8 BEST.&lt;BR /&gt;_00212110 Num 8 BEST.&lt;BR /&gt;SSBSQXJ0 Num 8 BEST.&lt;BR /&gt;SSBXBZB0 Num 8 BEST.&lt;BR /&gt;SSBYL6RK Num 8 BEST.&lt;BR /&gt;SSBYPC1T Num 8 BEST.&lt;BR /&gt;SSBZ0Y0T Num 8 BEST.&lt;BR /&gt;Y2106R11 Num 8 BEST.&lt;BR /&gt;Y2573F10 Num 8 BEST.&lt;BR /&gt;.......&lt;BR /&gt;&lt;BR /&gt;They are all numeric variables.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 22 Jan 2021 21:44:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713494#M220130</guid>
      <dc:creator>KS99</dc:creator>
      <dc:date>2021-01-22T21:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag values as many rows as designated, iteratively over all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713496#M220131</link>
      <description>&lt;P&gt;Thank you for your elaborate codes!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But my variables are over 4000, and they all have different names.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will keep your codes for the future reference, though&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;KS -,&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2021 21:48:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713496#M220131</guid>
      <dc:creator>KS99</dc:creator>
      <dc:date>2021-01-22T21:48:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag values as many rows as designated, iteratively over all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713513#M220140</link>
      <description>&lt;P&gt;My email anticipated this possibility, but you missed it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I repeat:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;For instance, if the first cusip variable name was, say "apple_cusip"&amp;nbsp; and the last was "xerox_cusip", and every variables between them were cusips of interest, you could generate the needed list using a double-dash, as in&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;array cusip_ids {*} apple_cusip--xerox_cusip;&lt;/STRONG&gt;&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp; But this assumes the cusip values are numeric, and cusip id's can have letters.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;This means you don't have to rename the variables.&amp;nbsp; &amp;nbsp;If the cusip variables are all side-by-side in the datasets, then all you need to know is the name of the left-most and right-most variable, and then use a double-dash.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In your case, say (from another of your comments) the left-most variable is&amp;nbsp;_00036020.&amp;nbsp; You don't provide the right-most, so let's call it&amp;nbsp; &amp;nbsp; Z13456676.&amp;nbsp; And again assuming all the variables between them are of interest, the array can be trivially constructed as&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array cusip_ids {*}   _00036020 -- Z13456676 ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Jan 2021 22:48:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713513#M220140</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-01-22T22:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag values as many rows as designated, iteratively over all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713550#M220154</link>
      <description>&lt;P&gt;Dear mkeintz,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now it works perfectly!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much , and Happy New Year!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sincerely,&amp;nbsp;&lt;/P&gt;&lt;P&gt;KS -,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jan 2021 03:12:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713550#M220154</guid>
      <dc:creator>KS99</dc:creator>
      <dc:date>2021-01-23T03:12:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag values as many rows as designated, iteratively over all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713582#M220167</link>
      <description>Make a macro ? or Using MERGE instead ?</description>
      <pubDate>Sat, 23 Jan 2021 10:40:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-values-as-many-rows-as-designated-iteratively-over/m-p/713582#M220167</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-01-23T10:40:57Z</dc:date>
    </item>
  </channel>
</rss>

