<?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 duplicate a value in SAS? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-duplicate-a-value-in-SAS/m-p/725287#M225245</link>
    <description>&lt;P&gt;Are you saying that you merely want to populate blank values of SEDOL with whatever non-blank precedes it (within a given gviidkey)?&amp;nbsp; I.e. are you merely trying to &lt;EM&gt;&lt;STRONG&gt;carry forward&lt;/STRONG&gt;&lt;/EM&gt; non-missing values?&amp;nbsp; If so, then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_:);
  set have;
  by gviidkey;
  retain _nonblnk_sedol '       ';   /*SEDOL takes 7 characters */
  if first.gviidkey=1 or sedol^=' ' then _nonblnk_sedol=sedol;
  if sedol=' ' then sedol=_nonblnk_sedol;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you ever have to carry sedol back from the future?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can SEDOL change over time for a given GVIIDKEY?&amp;nbsp; If so, what will you do if SEDOL is blank between two differing values from the previous and next years?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edited addition: you can be a little more economical, but a bit more obscure with:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_tst:);
  set have (rename=(sedol=_tst_sedol));
  by gviidkey;
  if _tst_sedol^=' ' then set have (where=(sedol^=' ') keep=sedol);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 11 Mar 2021 01:32:32 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2021-03-11T01:32:32Z</dc:date>
    <item>
      <title>How to duplicate a value in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-duplicate-a-value-in-SAS/m-p/725274#M225241</link>
      <description>&lt;P&gt;Hi all SAS Users.&lt;/P&gt;
&lt;P&gt;I want to duplicate the value in SAS as description below:&lt;/P&gt;
&lt;P&gt;I have a dataset report_firm_year_2d&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;gviidkey	year	LOC	s_yc_y	        APPDAYSUM	chl_y_c	        _0_returnday	SEDOL
001166_01W	1999	NLD	-0.000066294	253	        0	            1	            5165294
001166_01W	2000	NLD	-0.000088378	249	        0	            .	            5165294
001166_01W	2001	NLD	-0.000135834	252	        0	            .	            5165294
001166_02W	1999	NLD	-0.000103182	105	        0	            1      	        5584480
001166_02W	2000	NLD	0.0007173126	143      	0.0535653833	.	            5584480
001166_02W	2001	NLD	0.0001280852	84	        0.0226349455	.	            5584480
001855_03W	1999	PHL	0.0005017105	86	        0.0447977912	2	            BD0R0N4
001855_03W	2000	PHL	0.0013135089	42	        0.0724847262	.	
001855_03W	2001	PHL	0.0075094259	24	        0.173313888	    2	            BD0R0N4&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The column I want to focus here is gviidkey and SEDOL. As can be seen from the last column, the last three rows having the same gviidkey, what I want is to fill the second-to-last row of the last column by "BD0R0N4".&lt;/P&gt;
&lt;P&gt;Could you please hint me how to do that ?&lt;/P&gt;
&lt;P&gt;Warmest regards.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Mar 2021 21:44:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-duplicate-a-value-in-SAS/m-p/725274#M225241</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-03-10T21:44:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to duplicate a value in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-duplicate-a-value-in-SAS/m-p/725287#M225245</link>
      <description>&lt;P&gt;Are you saying that you merely want to populate blank values of SEDOL with whatever non-blank precedes it (within a given gviidkey)?&amp;nbsp; I.e. are you merely trying to &lt;EM&gt;&lt;STRONG&gt;carry forward&lt;/STRONG&gt;&lt;/EM&gt; non-missing values?&amp;nbsp; If so, then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_:);
  set have;
  by gviidkey;
  retain _nonblnk_sedol '       ';   /*SEDOL takes 7 characters */
  if first.gviidkey=1 or sedol^=' ' then _nonblnk_sedol=sedol;
  if sedol=' ' then sedol=_nonblnk_sedol;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you ever have to carry sedol back from the future?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can SEDOL change over time for a given GVIIDKEY?&amp;nbsp; If so, what will you do if SEDOL is blank between two differing values from the previous and next years?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edited addition: you can be a little more economical, but a bit more obscure with:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_tst:);
  set have (rename=(sedol=_tst_sedol));
  by gviidkey;
  if _tst_sedol^=' ' then set have (where=(sedol^=' ') keep=sedol);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Mar 2021 01:32:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-duplicate-a-value-in-SAS/m-p/725287#M225245</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-03-11T01:32:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to duplicate a value in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-duplicate-a-value-in-SAS/m-p/725288#M225246</link>
      <description>&lt;P&gt;"Second to last" is such an imprecise term and not very generic.&lt;/P&gt;
&lt;P&gt;Let's see if another "rule" works for your data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If a value is missing and the previous record is from the same "identification group" (how ever that may be defined) then replace the missing value with the previous assigned value for the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that rule is acceptable then this works for this example:&lt;/P&gt;
&lt;PRE&gt;data have;
 infile datalines  truncover;
 input gviidkey :$11. year LOC $3. s_yc_y APPDAYSUM chl_y_c _0_returnday SEDOL :$7.;
datalines;
001166_01W 1999 NLD -0.000066294 253 0	 1	 5165294
001166_01W 2000 NLD -0.000088378 249 0	 .	 5165294
001166_01W 2001 NLD -0.000135834 252 0	 .	 5165294
001166_02W 1999 NLD -0.000103182 105 0	 1 	 5584480
001166_02W 2000 NLD 0.0007173126 143 0.0535653833	.	 5584480
001166_02W 2001 NLD 0.0001280852 84 0.0226349455	.	 5584480
001855_03W 1999 PHL 0.0005017105 86 0.0447977912	2	 BD0R0N4
001855_03W 2000 PHL 0.0013135089 42 0.0724847262	.	 .
001855_03W 2001 PHL 0.0075094259 24 0.173313888	 2	 BD0R0N4
;

data want;
   set have;
   by gviidkey;
   length tempvar $ 7; /*long enough to hold values of SEDOL*/
   retain tempvar;
   if first.gviidkey then call missing(tempvar);
   if not missing(sedol) then tempvar=sedol;
   if missing(sedol) then sedol=tempvar;
   drop tempvar;
run;&lt;/PRE&gt;
&lt;P&gt;This will work for sequential missing values setting all of them the same.&lt;/P&gt;
&lt;P&gt;It will not work if the FIRST value for an id group is missing however. If you have that, then you need to provide a different example and the rules involved in a bit more generic form.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that if SEDOL value is always the same for the Gviidkey value and never assigned to a different Key it is practically a redundant variable (see data normalization).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This question gets asked in one form or another about 4 or 5 times per week. Specific details about "first" value per group and order of processing may have an impact.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please provide data in the form of a working data step. Mixed columns of tab and space separated junk takes time to clean up.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Mar 2021 22:31:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-duplicate-a-value-in-SAS/m-p/725288#M225246</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-10T22:31:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to duplicate a value in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-duplicate-a-value-in-SAS/m-p/725290#M225247</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your suggestion! I want to populate blank values of SEDOL with the SEDOL of the non-blank precedes or after it (within a given gviidkey)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example&lt;/P&gt;
&lt;P&gt;input&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;gviidkey       year        SEDOL
001166_01W     1999        5165294
001166_01W     2000        .
001166_01W     2001        5165294
001166_02W     1999        .
001166_02W     2000        5584480
001166_02W     2001        5584480
001855_03W     1999        .
001855_03W     2000        .
001855_03W     2001        .


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The result I want is&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;gviidkey       year        SEDOL
001166_01W     1999        5165294
001166_01W     2000        5165294
001166_01W     2001        5165294
001166_02W     1999        5584480
001166_02W     2000        5584480
001166_02W     2001        5584480
001855_03W     1999        .
001855_03W     2000        .
001855_03W     2001        .&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Warmest regards.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Mar 2021 22:46:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-duplicate-a-value-in-SAS/m-p/725290#M225247</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-03-10T22:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to duplicate a value in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-duplicate-a-value-in-SAS/m-p/725322#M225270</link>
      <description>&lt;P&gt;Assuming&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;data are sorted by gviidkey&lt;/LI&gt;
&lt;LI&gt;you never see a change in the SEDOL for a given GVIIDKEY (i.e. aside from blanks, there is no variation in the SEDOL value)&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;then a self-merge does exactly what you want:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge have  
        have (keep=gviidkey sedol where=(sedol^=' '));
  by gviidkey;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This does a match-merge of HAVE with a subset of HAVE.&amp;nbsp; The subset is only the non-blank SEDOL's.&amp;nbsp; Since for any given GVIIDKEY, there may be fewer non-blanks SEDOL's, their values wll be propagated through all of the "excess" records in the full sample.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 01:49:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-duplicate-a-value-in-SAS/m-p/725322#M225270</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-03-11T01:49:33Z</dc:date>
    </item>
  </channel>
</rss>

