<?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 create a forward variable ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724773#M225042</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212695"&gt;@Phil_NZ&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if ~eof then set have(firstobs=2 keep=weight rename=(weight=weight_lead1));
else weight_lead1=.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is the one that imports the data from the second dataset have to the dataset want?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Exactly. And&amp;nbsp;&lt;CODE class=" language-sas"&gt;have(firstobs=2 keep=weight rename=(weight=weight_lead1))&lt;/CODE&gt; &lt;EM&gt;is&lt;/EM&gt; the second dataset.&lt;/P&gt;</description>
    <pubDate>Tue, 09 Mar 2021 08:03:10 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2021-03-09T08:03:10Z</dc:date>
    <item>
      <title>How to create a forward variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724415#M224902</link>
      <description>&lt;P&gt;Hi SAS Users,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Normally, it is quite familiar to create a lag variable, can I ask &lt;STRONG&gt;how to create a forward variable&lt;/STRONG&gt;? And&lt;STRONG&gt; is there any chance to use the option firstobs=2&lt;/STRONG&gt; to do so?&lt;/P&gt;
&lt;P&gt;For example,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We have the dataset &lt;STRONG&gt;sashelp.class&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Name	Sex	Age	Height	Weight
Alfred	M	14	69	    112.5
Alice	F	13	56.5	84
Barbara	F	13	65.3	98
Carol	F	14	62.8	102.5
Henry	M	14	63.5	102.5
James	M	12	57.3	83
Jane	F	12	59.8	84.5
Janet	F	15	62.5	112.5
Jeffrey	M	13	62.5	84
John	M	12	59	    99.5
Joyce	F	11	51.3	50.5
Judy	F	14	64.3	90
Louise	F	12	56.3	77
Mary	F	15	66.5	112
Philip	M	16	72	    150
Robert	M	12	64.8	128
Ronald	M	15	67	    133
Thomas	M	11	57.5	85
William	M	15	66.5	112&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want to create a column &lt;STRONG&gt;weight_ lead1&lt;/STRONG&gt; while &lt;EM&gt;weight_lead1 is forward of weight (or in another word, weight is lag of weight_lead1)&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;For example&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Name	Sex	Age	Height	Weight   weight_lead1
Alfred	M	14	69	    112.5    84
Alice	F	13	56.5	84       98
Barbara	F	13	65.3	98       102.5
Carol	F	14	62.8	102.5    102.5
Henry	M	14	63.5	102.5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;83&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Could you please give me a hint or suggestion?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Warm regards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 07:58:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724415#M224902</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-03-08T07:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a forward variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724416#M224903</link>
      <description>&lt;P&gt;You are on the right track. For example consider:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
  merge HAVE
        HAVE (firstobs=2  /*keep= rename= options*/);
 /*no BY statement*/;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Mar 2021 08:02:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724416#M224903</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-03-08T08:02:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a forward variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724420#M224904</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your suggestion, But this without BY, SAS announces error&lt;/P&gt;
&lt;P&gt;The code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data uuu;
set sashelp.class;
run;

data WANT;
  merge uuu
        uuu (firstobs=2 keep=weight rename=(weight=weight_lead1));
 /*no BY statement*/;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And the LOG is as below&lt;/P&gt;
&lt;PRE&gt;32         data WANT;
33           merge uuu
34                 uuu (firstobs=2 keep=weight rename=(weight=weight_lead1));
35          /*no BY statement*/;
36         run;

ERROR: No BY statement was specified for a MERGE statement.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.WANT may be incomplete.  When this step was stopped there were 0 observations and 6 variables.
WARNING: Data set WORK.WANT was not replaced because this step was stopped.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Warm regards.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 08:08:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724420#M224904</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-03-08T08:08:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a forward variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724422#M224906</link>
      <description>&lt;P&gt;Use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mergenoby=nowarn;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;before the step.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 08:24:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724422#M224906</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-03-08T08:24:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a forward variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724426#M224910</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your suggestion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I apply this options and it run without any announcement about error.&lt;/P&gt;
&lt;P&gt;However, from what I understand, this option just for turning off the error announcement when merge without BY.&lt;/P&gt;
&lt;P&gt;From&lt;A href="https://www.lexjansen.com/nesug/nesug09/po/PO03.pdf" target="_self"&gt; this document&lt;/A&gt; from lexjansen.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Merging with no "BY statement" is &lt;EM&gt;&lt;STRONG&gt;dangerous&lt;/STRONG&gt;&lt;/EM&gt; unless it is a One-to-One merging (combines the first observation&lt;BR /&gt;from all data sets that are named in the MERGE statement into the first observation in the new data set, the&lt;BR /&gt;second observation from all data sets into the second observation in the new data set, and so on)&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So, I think of turning off this option right after running the code for this data step, because to me, when we assign a proc option, it will apply globally, so can you please help me to sort it out (turning off this option)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And I also think that, apart from the ERROR notification, the results with or without this option would be the same (I checked already, but just ask for confirmation)&lt;/P&gt;
&lt;P&gt;Warm regards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 08:41:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724426#M224910</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-03-08T08:41:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a forward variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724442#M224920</link>
      <description>&lt;P&gt;One other option would be "POINTing" next observation:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  set sashelp.class;
run;

data WANT;
  set have nobs=nobs;

  if _N_ &amp;lt; nobs 
    then set have(keep=weight rename=(weight=weight_lead1)) point = _N_;
    else weight_lead1 = .;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 09:39:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724442#M224920</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-03-08T09:39:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a forward variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724450#M224924</link>
      <description>&lt;P&gt;Or combine the two approaches and use &lt;FONT face="courier new,courier"&gt;firstobs=2&lt;/FONT&gt; in the second SET statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have end=eof;
if ~eof then set have(firstobs=2 keep=weight rename=(weight=weight_lead1));
else weight_lead1=.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Mar 2021 10:34:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724450#M224924</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-03-08T10:34:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a forward variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724574#M224953</link>
      <description>PROC EXPAND via SAS/ETS if you have a license for it. &lt;BR /&gt;&lt;BR /&gt;Otherwise the search term you're looking for is "LEAD" and if you search lexjansen.com for LEAD variables you'll find at least a dozen papers on the topic. &lt;BR /&gt;&lt;A href="https://www.lexjansen.com/search/searchresults.php?q=lead%20variable" target="_blank"&gt;https://www.lexjansen.com/search/searchresults.php?q=lead%20variable&lt;/A&gt;</description>
      <pubDate>Mon, 08 Mar 2021 17:39:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724574#M224953</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-08T17:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a forward variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724585#M224960</link>
      <description>&lt;P&gt;MERGE without BY could work, but since that is normally a mistake you need to clearly document your code and adjust the options that flag it as an error.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* Turn off MERGENOBY option for this step ;
%let save=%sysfunc(getoption(mergenoby,keyword));
options mergenoby=nowarn;
data want;
  merge have have(firstobs=2 keep=weight rename=(weight=weight_lead)) ;
run;
* Reset MERGENOBY option ;
options &amp;amp;save;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or just use two separate SET statements.&amp;nbsp; But then you need control for the different number of observations.&amp;nbsp; One way is to append some extra empty observations to match the number of skipped.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  set have(firstobs=2 keep=weight rename=(weight=weight_lead)) 
      have(obs=1 drop=_all_)
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now if your data is grouped you need a way to not take the value from the next group.&amp;nbsp; You could use LAST. flag to check for that and then clear the value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by id;
  set have(firstobs=2 keep=weight rename=(weight=weight_lead)) 
      have(obs=1 drop=_all_)
  ;
  if last.id then call missing(weight_lead);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 18:23:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724585#M224960</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-08T18:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a forward variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724588#M224962</link>
      <description>&lt;P&gt;If you want to LEAD2, LEAD3, etc then you will need a different method to detect when the values should be cleared because you have reached the end of the group.&amp;nbsp; In that case keep the ID variable also and test it.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input id @;
 do row=1 to 5 ; input x @; output; end;
cards;
1 1 2 3 4 5
2 11 12 13 14 15
;

data want;
   set have;
   by id;
   set have(firstobs=2 keep=id x rename=(id=id1 x=x1)) have(obs=1 drop=_all_);
   set have(firstobs=3 keep=id x rename=(id=id2 x=x2)) have(obs=2 drop=_all_);
   set have(firstobs=4 keep=id x rename=(id=id3 x=x3)) have(obs=3 drop=_all_);
   if id1 ne id then call missing(x1);
   if id2 ne id then call missing(x2);
   if id3 ne id then call missing(x3);
   drop id1-id3;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    id    row     x    x1    x2    x3

  1     1     1      1     2     3     4
  2     1     2      2     3     4     5
  3     1     3      3     4     5     .
  4     1     4      4     5     .     .
  5     1     5      5     .     .     .
  6     2     1     11    12    13    14
  7     2     2     12    13    14    15
  8     2     3     13    14    15     .
  9     2     4     14    15     .     .
 10     2     5     15     .     .     .
&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Mar 2021 18:33:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724588#M224962</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-08T18:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a forward variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724620#M224973</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;So, I think of turning off this option right after running the code for this data step, because to me, when we assign a proc option, it will apply globally, so can you please help me to sort it out (turning off this option)?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your administrator decided that this option was a safer default.&lt;/P&gt;
&lt;P&gt;In your case, you know what you want and what you are doing (one-to-one merge), so you needed to disable it before the data step, and you can re-enable it after the data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another way, as shown, is to use two SET statements.&lt;/P&gt;
&lt;P&gt;I would not use the suggestion that uses POINT= though. It is good that it is presented to you so you know about it, but know that POINT= is very slow.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 20:48:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724620#M224973</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-03-08T20:48:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a forward variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724631#M224978</link>
      <description>&lt;P&gt;True, POINT= is slower, but on the other hand it allow non-sequential read, e.g you can read dataset backward without resorting it. And for small datasets (up to 1 million obs.) the difference in performance is almost&amp;nbsp;&lt;SPAN&gt;intangible.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Like everywhere in programming something for something. &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;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 20:19:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724631#M224978</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-03-08T20:19:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a forward variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724656#M224990</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp; (Bart)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your solution, Your code leads me to the very nice &lt;A href="https://www.lexjansen.com/sesug/2019/SESUG2019_Paper-128_Final_PDF.pdf" target="_self"&gt;&lt;STRONG&gt;nobs=nobs&lt;/STRONG&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, I have two concerns here in your code, could you please help me to sort it out?&lt;/P&gt;
&lt;P&gt;1. When I run the code in my head, let's say the first iteration:&lt;/P&gt;
&lt;P&gt;_N_=1 /* From &lt;A href="https://sasnrd.com/sas-automatic-n-variable/#:~:text=According%20to%20the%20SAS%20Data,the%20data%20step%20has%20iterated.&amp;amp;text=This%20means%20that%20the%20data%20step%20iterates%20three%20times." target="_self"&gt;this document&lt;/A&gt; &lt;SPAN&gt;_N_ variable increments by one each time the data step passes by a data statement&lt;/SPAN&gt;*/&lt;/P&gt;
&lt;P&gt;then set&amp;nbsp; have() point = 1&lt;/P&gt;
&lt;P&gt;else weight_lead1=.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not understand how SAS create values for data WANT here ( there is no hint for the&lt;STRONG&gt; lead&lt;/STRONG&gt; condition to me), could you please explain the mechanism to me?&lt;/P&gt;
&lt;P&gt;2. When I copy and run your code without any adjustment, the error is as below&lt;/P&gt;
&lt;PRE&gt;32         data WANT;
33           set have nobs=nobs;
34         
35           if _N_ &amp;lt; nobs
36             then set have(keep=weight rename=(weight=weight_lead1)) point = _N_;
37             else weight_lead1 = .;
38         run;

ERROR: The POINT= data set option is not valid for the data set WORK.HAVE, the data set must be accessible by observation number 
       for POINT= processing.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.WANT may be incomplete.  When this step was stopped there were 0 observations and 6 variables.
WARNING: Data set WORK.WANT was not replaced because this step was stopped.&lt;/PRE&gt;
&lt;P&gt;Could you please help me to sort it out?&lt;/P&gt;
&lt;P&gt;Warm regards.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 21:11:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724656#M224990</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-03-08T21:11:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a forward variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724662#M224991</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your suggestion. I learn more about the option &lt;A href="https://communities.sas.com/t5/SAS-Programming/What-is-the-purpose-of-end-eof/td-p/565139" target="_self"&gt;end=eof&lt;/A&gt;. The code runs flawlessly.&lt;/P&gt;
&lt;P&gt;But I still confuse how the data want receive the value of weight.lead1.&lt;/P&gt;
&lt;P&gt;For example, let's say the first iteration.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
/*_N_=1 for the first iteration*/
set sashelp.class end=eof;
/*end=19 (size of sashelp.class)*/
if ~eof then set sashelp.class(firstobs=2 keep=weight rename=(weight=weight_lead1));
/* if not the last observation of sashelp.class  then &lt;STRONG&gt;what ???&lt;/STRONG&gt;*/
else weight_lead1=.;/*Last obs receive missing value*/
run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data want;
/*_N_=2 for the second iteration*/
set sashelp.class end=eof;
/*end=19 (size of sashelp.class)*/
if ~eof then set sashelp.class(firstobs=2 keep=weight rename=(weight=weight_lead1));
/* if not the last observation of sashelp.class  then &lt;STRONG&gt;what ???&lt;/STRONG&gt;*/
else weight_lead1=.;/*Last obs receive missing value*/
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I am stuck in the bold place in this code, could you please help me to sort it out?&lt;/P&gt;
&lt;P&gt;Warm regards.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 21:31:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724662#M224991</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-03-08T21:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a forward variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724664#M224992</link>
      <description>&lt;P&gt;About 2)&lt;/P&gt;
&lt;P&gt;From the doc:&lt;/P&gt;
&lt;TABLE class="xisDoc-summary"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="xisDoc-restriction" rowspan="2"&gt;Restrictions&lt;/TH&gt;
&lt;TD class="xisDoc-summaryText"&gt;You cannot use POINT= with a BY statement, a WHERE statement, or a WHERE= data set option. In addition, &lt;STRONG&gt;you cannot use POINT= with transport format data sets, data sets in sequential format on tape or disk, and&amp;nbsp;&lt;SPAN class="xisDoc-nobr"&gt;SAS/ACCESS&lt;/SPAN&gt;&amp;nbsp;views or the SQL procedure views that read data from external files&lt;/STRONG&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;Maybe your file is one of that case? Try to run &lt;STRONG&gt;proc contents&lt;/STRONG&gt;&amp;nbsp;on the HAVE and see the output, is the "Point to Observations" set to Yes?&lt;/P&gt;
&lt;P&gt;Other possibility is that you have compress option on (like in this thread &lt;A href="https://communities.sas.com/t5/SAS-Procedures/Point-error/td-p/144266)" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/Point-error/td-p/144266)&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;About 1)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The &lt;EM&gt;nobs&lt;/EM&gt; value is extracted in the compilation time. So you can "almost" imagine this code like (assuming that HAVE has 19 observations):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
  set have nobs=nobs; /* FIRST set */

  if _N_ &amp;lt; 19 /* nobs - this value is known in compilation phase */
    then set have(keep=weight rename=(weight=weight_lead1)) point = _N_; /* SECOND set */
    else weight_lead1 = .;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so &lt;EM&gt;the second&lt;/EM&gt; set reading is executed only for observations 1 to 18 from &lt;EM&gt;the first set&lt;/EM&gt;, and when _N_=19 the "else" is executed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way, I just realised I made a mistake in the code, sorry for that. It should be as follows (the observation pointed should be _N_+1):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  set sashelp.class;
run;

data WANT;
  set have nobs=nobs;

  if _N_ &amp;lt; nobs then
    do;
      point = _N_+1;
      set have(keep=weight rename=(weight=weight_lead1)) point = point;
    end;
    else weight_lead1 = .;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope it helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 21:43:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724664#M224992</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-03-08T21:43:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a forward variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724684#M225000</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is a breath-taking solution to me!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Well ,I found a document, and after applying to my code, I get things easily.&lt;/P&gt;
&lt;P&gt;Normally, I need to use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;lagx=ifn(first.id,.,lag(x));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but proc convert can do all of things (set the first.id =. automatically), the same with lead (set the last.id=.).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are two minor questions here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Can you please tell me what do you mean about "&lt;SPAN&gt;if you ha&lt;/SPAN&gt;&lt;SPAN&gt;ve a license for it" , it is "for SAS" or for what, please?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2. When I run the code below&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data uuu;
set sashelp.class;
run;
proc sort data=uuu;
by sex;
run;

proc expand data=uuu method=none;
	by Sex;
	convert weight=weight_lead1 / transformout=(lead 1);
	convert weight=weight_lead2 / transformout=(lead 2);
	convert weight=weight_lag1 / transformout=(lag 1);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;The result is as below&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="My97_0-1615242946406.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55683i2ACFC654C59F9162/image-size/medium?v=v2&amp;amp;px=400" role="button" title="My97_0-1615242946406.png" alt="My97_0-1615242946406.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;There is column name TIME coming from nowhere, can you please explain to me what it is for and why it exists in my output like that?&lt;/P&gt;
&lt;P&gt;Warmest regard and thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 22:37:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724684#M225000</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-03-08T22:37:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a forward variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724685#M225001</link>
      <description>Hence why you should turn off the option before the step and turn it on again after.&lt;BR /&gt;</description>
      <pubDate>Mon, 08 Mar 2021 22:53:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724685#M225001</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-03-08T22:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a forward variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724692#M225004</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;1. Can you please tell me what do you mean about "&lt;SPAN&gt;if you ha&lt;/SPAN&gt;&lt;SPAN&gt;ve a license for it" , it is "for SAS" or for what, please?&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;SAS has different modules, EXPAND is part of the ETS module. You can choose which modules to have installed or licensed. ETS is &lt;STRONG&gt;E&lt;/STRONG&gt;conometrics and &lt;STRONG&gt;T&lt;/STRONG&gt;ime &lt;STRONG&gt;S&lt;/STRONG&gt;eries&lt;/P&gt;
&lt;P&gt;SAS/OR is Operations Research for example.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Different modules include different procs. If you're familiar with R/Python, its similar to different packages or libraries for different types of analysis.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC EXPAND is designed for time series data. If you think about it, when using LEAD you usually need some kind of variable that represents an order or time, not just the implication of the row position. What happens if you have missing data?&lt;/P&gt;
&lt;P&gt;You're currently using a mock example which is unrealistic in that regard. The leading row in that case has no business or logical context, whereas looking at the future or previous value for sales could be informative. If you have a use case that is similar you can either add a mock time variable to get the same functionality or it generates it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 23:09:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724692#M225004</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-08T23:09:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a forward variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724700#M225007</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is just because I turn off the notice by using&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mernoby=nowarn;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to compress the error notification and then just recognize that this options stuff will apply globally in my SAS EG ,so I try to turn the notice on again by&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mernoby=warn;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Simplistically speaking, it is a newbie's mistake.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Warm regards.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 23:19:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724700#M225007</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-03-08T23:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a forward variable ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724702#M225008</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212695"&gt;@Phil_NZ&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your suggestion. I learn more about the option &lt;A href="https://communities.sas.com/t5/SAS-Programming/What-is-the-purpose-of-end-eof/td-p/565139" target="_self"&gt;end=eof&lt;/A&gt;. The code runs flawlessly.&lt;/P&gt;
&lt;P&gt;But I still confuse how the data want receive the value of weight.lead1.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You can think of the two SET statements as reading from two separate datasets:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;FONT face="courier new,courier"&gt;sashelp.class&lt;/FONT&gt; (19 obs.)&lt;/LI&gt;
&lt;LI&gt;a dataset consisting of only the &lt;FONT face="courier new,courier"&gt;weight&lt;/FONT&gt; values of all but the first observation of&amp;nbsp;&lt;FONT face="courier new,courier"&gt;sashelp.class&lt;/FONT&gt; (i.e. 18 obs.), with &lt;FONT face="courier new,courier"&gt;weight_lead1&lt;/FONT&gt; as the name of that single variable.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;In the first iteration of the DATA step -- &lt;FONT face="courier new,courier"&gt;_N_=1&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;eof=&lt;FONT size="4"&gt;&lt;STRONG&gt;0&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;, hence &lt;FONT face="courier new,courier"&gt;~eof=&lt;FONT size="4"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&amp;nbsp;-- the first SET statement reads the first observation of the first dataset and the second SET statement reads the first observation of the second dataset (which contains the &lt;FONT face="courier new,courier"&gt;weight&lt;/FONT&gt; value of the second observation of &lt;FONT face="courier new,courier"&gt;sashelp.class&lt;/FONT&gt;&amp;nbsp;in variable&amp;nbsp;&lt;FONT face="courier new,courier"&gt;weight_lead1&lt;/FONT&gt;). So, at the end of the first iteration the program data vector contains the values of the first observation of&amp;nbsp;&lt;FONT face="courier new,courier"&gt;sashelp.class&lt;/FONT&gt; and&amp;nbsp;in variable&amp;nbsp;&lt;FONT face="courier new,courier"&gt;weight_lead1&lt;/FONT&gt;&amp;nbsp;the desired "lead" value of variable&amp;nbsp;&lt;FONT face="courier new,courier"&gt;weight&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the second iteration of the DATA step -- &lt;FONT face="courier new,courier"&gt;_N_=2&lt;/FONT&gt;, still&amp;nbsp;&lt;FONT face="courier new,courier"&gt;eof=&lt;FONT size="4"&gt;0&lt;/FONT&gt;&lt;/FONT&gt;, hence &lt;FONT face="courier new,courier"&gt;~eof=&lt;FONT size="4"&gt;1&lt;/FONT&gt;&lt;/FONT&gt;&amp;nbsp;-- the first SET statement reads the second observation of the first dataset and the second SET statement reads the second observation of the second dataset (which contains the &lt;FONT face="courier new,courier"&gt;weight&lt;/FONT&gt; value of the third observation of &lt;FONT face="courier new,courier"&gt;sashelp.class&lt;/FONT&gt;&amp;nbsp;in variable&amp;nbsp;&lt;FONT face="courier new,courier"&gt;weight_lead1&lt;/FONT&gt;). So, at the end of the second iteration the program data vector contains the values of the second observation of&amp;nbsp;&lt;FONT face="courier new,courier"&gt;sashelp.class&lt;/FONT&gt; and, again, in variable&amp;nbsp;&lt;FONT face="courier new,courier"&gt;weight_lead1&lt;/FONT&gt;&amp;nbsp;the desired "lead" value of variable&amp;nbsp;&lt;FONT face="courier new,courier"&gt;weight&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;... and so on until the 18th observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the 19th iteration of the DATA step -- &lt;FONT face="courier new,courier"&gt;_N_=19&lt;/FONT&gt;, at the beginning still&amp;nbsp;&lt;FONT face="courier new,courier"&gt;eof=&lt;FONT size="4"&gt;0&lt;/FONT&gt;&lt;/FONT&gt;&amp;nbsp;-- the first SET statement reads the last (=19th) observation of the first dataset, the value of &lt;FONT face="courier new,courier"&gt;eof&lt;/FONT&gt; is switched to &lt;FONT face="courier new,courier"&gt;&lt;FONT size="4"&gt;1&lt;/FONT&gt;&lt;/FONT&gt;, hence &lt;FONT face="courier new,courier"&gt;~eof=&lt;FONT size="4"&gt;0&lt;/FONT&gt;&lt;/FONT&gt;, and therefore the second SET statement &lt;EM&gt;is not executed&lt;/EM&gt;, which is good because reading past the end of the dataset (remember that the second dataset has only 18 observations, the last of which has already been read in the previous iteration of the DATA step) would cause the DATA step to terminate immediately. That is, dataset WANT would have only 18 observations (the observation with&amp;nbsp;&lt;FONT face="courier new,courier"&gt;name='William'&lt;/FONT&gt; would be missing). Now, with &lt;FONT face="courier new,courier"&gt;~eof&lt;/FONT&gt; being false (&lt;FONT face="courier new,courier"&gt;&lt;FONT size="4"&gt;0&lt;/FONT&gt;&lt;/FONT&gt;), the ELSE branch is executed instead and overwrites the retained value of &lt;FONT face="courier new,courier"&gt;weight_lead1&lt;/FONT&gt;&amp;nbsp;(&lt;FONT face="courier new,courier"&gt;=112&lt;/FONT&gt;, from the last observation of the second dataset -- remember that variables read by a SET statement are automatically retained) with a missing value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the last (=20th!) iteration of the DATA step&amp;nbsp;-- &lt;FONT face="courier new,courier"&gt;_N_=20&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;eof=&lt;FONT size="4"&gt;1&lt;/FONT&gt;&lt;/FONT&gt;&amp;nbsp;-- the first SET statement reads past the end of the first dataset and this terminates the DATA step. So, the 19th observation of dataset WANT (written at the end of the 19th iteration) is also the last.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 23:32:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-forward-variable/m-p/724702#M225008</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-03-08T23:32:20Z</dc:date>
    </item>
  </channel>
</rss>

