<?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: shifts up not missing variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/shifts-up-not-missing-variables/m-p/515214#M73233</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input var1 var2;
cards;
1 4
2 9
3 .
4 .
5 .
3 .
; 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 21 Nov 2018 19:15:40 GMT</pubDate>
    <dc:creator>mansour_ib_sas</dc:creator>
    <dc:date>2018-11-21T19:15:40Z</dc:date>
    <item>
      <title>shifts up not missing variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/shifts-up-not-missing-variables/m-p/515208#M73230</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hello, &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I want to shifts up the var2 this data. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For that, I use the option next. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I&amp;nbsp;have two problems, &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I can not define the beginning of the missing values ​​and their end. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;here is an example &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input var1 var2;
cards;
1 .
2 .
3 .
4 .
5 4
3 9
; 
run;


data test1;
set test end=eof;
next=_n_+4;
if not eof then set test (keep=var2 rename=(var2=next_var2 )) point=next;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Thank you&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Nov 2018 19:06:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/shifts-up-not-missing-variables/m-p/515208#M73230</guid>
      <dc:creator>mansour_ib_sas</dc:creator>
      <dc:date>2018-11-21T19:06:50Z</dc:date>
    </item>
    <item>
      <title>Re: shifts up not missing variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/shifts-up-not-missing-variables/m-p/515211#M73231</link>
      <description>&lt;P&gt;What is your expected output ?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Nov 2018 19:13:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/shifts-up-not-missing-variables/m-p/515211#M73231</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2018-11-21T19:13:50Z</dc:date>
    </item>
    <item>
      <title>Re: shifts up not missing variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/shifts-up-not-missing-variables/m-p/515212#M73232</link>
      <description>&lt;P&gt;+1 mate!&lt;/P&gt;</description>
      <pubDate>Wed, 21 Nov 2018 19:14:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/shifts-up-not-missing-variables/m-p/515212#M73232</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-21T19:14:27Z</dc:date>
    </item>
    <item>
      <title>Re: shifts up not missing variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/shifts-up-not-missing-variables/m-p/515214#M73233</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input var1 var2;
cards;
1 4
2 9
3 .
4 .
5 .
3 .
; 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Nov 2018 19:15:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/shifts-up-not-missing-variables/m-p/515214#M73233</guid>
      <dc:creator>mansour_ib_sas</dc:creator>
      <dc:date>2018-11-21T19:15:40Z</dc:date>
    </item>
    <item>
      <title>Re: shifts up not missing variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/shifts-up-not-missing-variables/m-p/515217#M73234</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data test;
input var1 var2;
cards;
1 .
2 .
3 .
4 .
5 4
3 9
; 
run;


data test1;
merge test(drop=var2)  test(keep=var2 where=(var2 is not missing)) ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Nov 2018 19:22:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/shifts-up-not-missing-variables/m-p/515217#M73234</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-21T19:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: shifts up not missing variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/shifts-up-not-missing-variables/m-p/515330#M73238</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data test;
input var1 var2;
cards;
1 .
2 .
3 .
4 .
5 4
3 9
; 
run;


data test1;
merge test(drop=var2)  test(keep=var2 firstobs=5) ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Nov 2018 12:24:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/shifts-up-not-missing-variables/m-p/515330#M73238</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-11-22T12:24:33Z</dc:date>
    </item>
    <item>
      <title>Re: shifts up not missing variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/shifts-up-not-missing-variables/m-p/515841#M73248</link>
      <description>&lt;P&gt;And what if the OP wanted:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input var1 var2;
cards;
1 4
2 9
3 9
4 9
5 9
3 9
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 25 Nov 2018 22:44:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/shifts-up-not-missing-variables/m-p/515841#M73248</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-11-25T22:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: shifts up not missing variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/shifts-up-not-missing-variables/m-p/515846#M73249</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
merge test(drop=var2)  test(keep=var2 where=(var2 is not missing)) ;
retain _iorc_;
if not missing(var2) then _iorc_=var2;
else var2=_iorc_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 25 Nov 2018 23:00:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/shifts-up-not-missing-variables/m-p/515846#M73249</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-25T23:00:29Z</dc:date>
    </item>
    <item>
      <title>Re: shifts up not missing variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/shifts-up-not-missing-variables/m-p/515847#M73250</link>
      <description>&lt;P&gt;An easy way to retain a SET (or MERGE) variable across multiple observations is to do conditional SET statements:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input var1 var2;
cards;
1 .
2 .
3 .
4 .
5 4
3 9
run;

data want;
  set have (drop=var2);
  if eod2=0 then set have (keep=var2 where=(not missing(var2))) end=eod2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;VAR2, like all variables read by SET or MERGE, is automatically retained until a subsequent data step iteration executes a SET or MERGE retrieving the same variable and overwrites the old value.&amp;nbsp; Simply avoid any attempt to read var2 beyond end of data set HAVE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;While there's not much advantage in the case of a single VAR2 variables, consider the advantages when there are, say, a dozen variables that are simultaneously all missing or all non-missing and all need to be "shifted up".&lt;/P&gt;</description>
      <pubDate>Sun, 25 Nov 2018 23:10:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/shifts-up-not-missing-variables/m-p/515847#M73250</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-11-25T23:10:51Z</dc:date>
    </item>
    <item>
      <title>Re: shifts up not missing variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/shifts-up-not-missing-variables/m-p/515849#M73251</link>
      <description>&lt;P&gt;Nice&lt;/P&gt;</description>
      <pubDate>Sun, 25 Nov 2018 23:15:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/shifts-up-not-missing-variables/m-p/515849#M73251</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-25T23:15:59Z</dc:date>
    </item>
    <item>
      <title>Re: shifts up not missing variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/shifts-up-not-missing-variables/m-p/515950#M73253</link>
      <description>&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;in this example, why i have a 12 observations in t3 and only 6 in want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input var1 var2;
cards;
1 .
2 .
3 .
4 .
5 4
3 9
run;

data t1;
set want(keep=var1);
run;

data t2;
set want(keep=var2);
run;

data t3;
set t1 t2;
run;

data want;
  set have (drop=var2);
  set have (keep=var2);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;another question please.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;is&amp;nbsp; eod2 own for this statement only or for data result (want)?&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; have &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;keep&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;var2 &lt;SPAN class="token statement"&gt;where&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;not&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;missing&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;var2&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; end&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;eod2&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;SPAN&gt;if so, could you, please, explain to me how he had to go "shift up" the observations of var2&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Nov 2018 11:39:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/shifts-up-not-missing-variables/m-p/515950#M73253</guid>
      <dc:creator>mansour_ib_sas</dc:creator>
      <dc:date>2018-11-26T11:39:36Z</dc:date>
    </item>
    <item>
      <title>Re: shifts up not missing variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/shifts-up-not-missing-variables/m-p/516012#M73255</link>
      <description>&lt;P&gt;When you have a statement like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET A B;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you are creating a single stream of data by concatenating observations in A , followed by observations in B.&amp;nbsp; It doesn't matter that A and B don't have the&amp;nbsp; same variables, you will still get Na+Nb observations (where Na is number of obs in A, and Nb is defined similarly).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET A;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET B;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;generates two synchronized streams, so the number of obs will be the minimum of Na vs Nb.&amp;nbsp;&amp;nbsp; (The data step stops when either SET statement attempts to read beyond end of data.&amp;nbsp; Of&amp;nbsp; course any&amp;nbsp; variable in both B and&amp;nbsp; A will get the value from B overwriting the value from A.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; MERGE A B;&lt;/P&gt;
&lt;P&gt;makes a (let's call it) a single merged stream.&amp;nbsp; It will produce the same results&amp;nbsp; as "SET A; SET B;",&amp;nbsp; EXCEPT anytime&amp;nbsp; Na^=Nb, there will be additional observations generating a&amp;nbsp; total number of observations equal to the&amp;nbsp; MAXIMUM of Na vs Nb. &amp;nbsp; And those extra observations will have missing values assigned to variables belonging only to the smaller dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;These are very powerful capabilities of the SAS data step, which is often able to trivially generate results attainable in proc sql only by very tortured coding.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As to the question on the "end=" option of the SET statement, that is a question (unlike the above) which can easily be answered by the sas documentation, or a google search for&amp;nbsp;&amp;nbsp; sas+set+end.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Nov 2018 15:17:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/shifts-up-not-missing-variables/m-p/516012#M73255</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-11-26T15:17:27Z</dc:date>
    </item>
  </channel>
</rss>

