<?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: Dynamic Imputation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Imputation/m-p/67477#M14598</link>
    <description>Looks like data I sometimes get from EXCEL.  I assume your starting point is a SAS data set.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data have;&lt;BR /&gt;
   input x $ y @@;&lt;BR /&gt;
   cards;&lt;BR /&gt;
A 2 . 4 . 6 . 8 . 10&lt;BR /&gt;
B 1 . 2 &lt;BR /&gt;
C 1 . 2 . 3 . 4&lt;BR /&gt;
;;;;&lt;BR /&gt;
   run;&lt;BR /&gt;
data need;&lt;BR /&gt;
   if 0 then set have(keep=x);&lt;BR /&gt;
   set have(rename=(x=_x));&lt;BR /&gt;
   x = coalesceC(_x,x);&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
You can drop _X&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
Obs    x    _x     y&lt;BR /&gt;
&lt;BR /&gt;
  1    A    A      2&lt;BR /&gt;
  2    A           4&lt;BR /&gt;
  3    A           6&lt;BR /&gt;
  4    A           8&lt;BR /&gt;
  5    A          10&lt;BR /&gt;
  6    B    B      1&lt;BR /&gt;
  7    B           2&lt;BR /&gt;
  8    C    C      1&lt;BR /&gt;
  9    C           2&lt;BR /&gt;
 10    C           3&lt;BR /&gt;
 11    C           4&lt;BR /&gt;
[/pre]</description>
    <pubDate>Mon, 15 Mar 2010 18:07:13 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2010-03-15T18:07:13Z</dc:date>
    <item>
      <title>Dynamic Imputation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Imputation/m-p/67470#M14591</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I have the data as follows. Suppose it has 2 variables X and Y and the values are as below&lt;BR /&gt;
&lt;BR /&gt;
X         Y&lt;BR /&gt;
A         2&lt;BR /&gt;
           4&lt;BR /&gt;
           6&lt;BR /&gt;
           8&lt;BR /&gt;
          10&lt;BR /&gt;
B         1&lt;BR /&gt;
            2&lt;BR /&gt;
C         1&lt;BR /&gt;
           2&lt;BR /&gt;
           3&lt;BR /&gt;
           4&lt;BR /&gt;
&lt;BR /&gt;
and something like that....The missing value for variable X from row 2 to row 5 is A and the missing value for variable X in row 7 is B and the missing value for variable X from row 9 to 12 is C. What should I do to fill in the appropriate value in place of the missing values. The above dataset is just an example. In my actual data I have 89 different values for variable X and the number of missing values under it keep on changing. &lt;BR /&gt;
&lt;BR /&gt;
Can someone please let me know what is an effective way to solve this problem ( the code has to be dynamic). Thanks in advance!&lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;BR /&gt;
Sohail Mohammad</description>
      <pubDate>Thu, 11 Mar 2010 22:31:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Imputation/m-p/67470#M14591</guid>
      <dc:creator>Soha</dc:creator>
      <dc:date>2010-03-11T22:31:07Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Imputation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Imputation/m-p/67471#M14592</link>
      <description>Using a DATA step and a DO UNTIL(EOF);  with an INFILE and END=EOF coded, you can input the data record and detect when you have one or two field values.  When you have one value, do not overlay "X", only overlap/replace "Y", and only perform your OUTPUT when you have the correct data/variable condition.  Some functions you will consider using are SCAN and also INPUT when assigning your true "X" and "Y" variables.  If you iterate your DATA step with the DO/END and having the INPUT within the code portion, you then do not need to use the RETAIN statement since SAS will not return to the top of the DATA step.&lt;BR /&gt;
&lt;BR /&gt;
Suggest you track your program with some well-placed PUTLOG '&amp;gt;diag-nnn&amp;gt;' / _ALL_;  commands within your DO / END programming loop.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Recommended Google advanced search arguments, this topic/post:&lt;BR /&gt;
&lt;BR /&gt;
data step programming external data site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
data step parse external data input function site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
data step parse external data _infile_ site:sas.com</description>
      <pubDate>Thu, 11 Mar 2010 23:24:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Imputation/m-p/67471#M14592</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-03-11T23:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Imputation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Imputation/m-p/67472#M14593</link>
      <description>It's a simple data step.&lt;BR /&gt;
&lt;BR /&gt;
data XXXX (drop = XorYisvoid voidValue);&lt;BR /&gt;
set YourFile;&lt;BR /&gt;
&lt;BR /&gt;
If x eq ''  then XorTisvoid = 'X';&lt;BR /&gt;
else XorTisvoid = 'y';&lt;BR /&gt;
&lt;BR /&gt;
if XorTisvoid = 'X' then do;&lt;BR /&gt;
  if voidvalue ne X then  voidvalue =x;&lt;BR /&gt;
  Y = voidvalue;&lt;BR /&gt;
end;&lt;BR /&gt;
else do;&lt;BR /&gt;
  if voidvalue ne Y then  voidvalue =y;&lt;BR /&gt;
  Y = voidvalue;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
I programed it by memory but i think it's a fine base to start</description>
      <pubDate>Fri, 12 Mar 2010 12:43:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Imputation/m-p/67472#M14593</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-03-12T12:43:55Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Imputation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Imputation/m-p/67473#M14594</link>
      <description>I don't know why the data was posted that way...I dint mean to show up that way.&lt;BR /&gt;
&lt;BR /&gt;
Actually the missing values are for X and the numeric values that show up under variable X is for variable Y.&lt;BR /&gt;
&lt;BR /&gt;
So, the data is liek this:&lt;BR /&gt;
Variable X: 'A' '&lt;MISSING&gt;'  '&lt;MISSING&gt;' '&lt;MISSING&gt;' '&lt;MISSING&gt;' 'B' '&lt;MISSING&gt;' 'C' '&lt;MISSING&gt;'&lt;MISSING&gt;' '&lt;MISSING&gt;'&lt;BR /&gt;
&lt;BR /&gt;
and the corresponding values for variable Y are: 2 4 6 8 10 1 2 1 2 3 4&lt;BR /&gt;
&lt;BR /&gt;
All the missing values between 'A' and 'B' should be imputed with 'A' and all the missing values between 'B' and 'C' should be imputed with 'B' and so on....&lt;BR /&gt;
&lt;BR /&gt;
@sasvage: What are the variables you are dropping in your data step option? Can you please elaborate?&lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;BR /&gt;
Sohail Mohammad&lt;/MISSING&gt;&lt;/MISSING&gt;&lt;/MISSING&gt;&lt;/MISSING&gt;&lt;/MISSING&gt;&lt;/MISSING&gt;&lt;/MISSING&gt;&lt;/MISSING&gt;</description>
      <pubDate>Fri, 12 Mar 2010 22:19:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Imputation/m-p/67473#M14594</guid>
      <dc:creator>Soha</dc:creator>
      <dc:date>2010-03-12T22:19:45Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Imputation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Imputation/m-p/67474#M14595</link>
      <description>Soha&lt;BR /&gt;
&lt;BR /&gt;
It might be worth to consult the excellent SAS Docu: &lt;A href="http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a000146292.htm" target="_blank"&gt;http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a000146292.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
From your example data given I assume that column input would solve your problem: &lt;BR /&gt;
(I had to add this 'x' in order to post a working example).&lt;BR /&gt;
&lt;BR /&gt;
data have;&lt;BR /&gt;
  infile datalines truncover;&lt;BR /&gt;
  input @3 x $   @5 y;&lt;BR /&gt;
  datalines;&lt;BR /&gt;
x A 2&lt;BR /&gt;
x   4&lt;BR /&gt;
x   6&lt;BR /&gt;
x   8&lt;BR /&gt;
x   10&lt;BR /&gt;
x B 1&lt;BR /&gt;
x   2&lt;BR /&gt;
x C 1&lt;BR /&gt;
x   2&lt;BR /&gt;
x   3&lt;BR /&gt;
x   4&lt;BR /&gt;
;&lt;BR /&gt;
proc print data=have;&lt;BR /&gt;
run;</description>
      <pubDate>Sat, 13 Mar 2010 06:06:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Imputation/m-p/67474#M14595</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-03-13T06:06:43Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Imputation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Imputation/m-p/67475#M14596</link>
      <description>Hi Soha,&lt;BR /&gt;
&lt;BR /&gt;
Is your data an external file? maybe you can use @ functions:&lt;BR /&gt;
&lt;BR /&gt;
data x(drop=z);&lt;BR /&gt;
	infile 'c:\xy.txt' dlm =' ' firstobs=2;&lt;BR /&gt;
	length x $8. y 8.;&lt;BR /&gt;
	input @1 x $ @;&lt;BR /&gt;
		retain z;&lt;BR /&gt;
		if indexc(x,'12345667890')=0 then do;&lt;BR /&gt;
			input @3 y;&lt;BR /&gt;
			z=x;&lt;BR /&gt;
		end;&lt;BR /&gt;
		else do;&lt;BR /&gt;
			x=z;&lt;BR /&gt;
			input @1 y;&lt;BR /&gt;
		end;&lt;BR /&gt;
run;</description>
      <pubDate>Mon, 15 Mar 2010 04:31:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Imputation/m-p/67475#M14596</guid>
      <dc:creator>fafajoe</dc:creator>
      <dc:date>2010-03-15T04:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Imputation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Imputation/m-p/67476#M14597</link>
      <description>I explain,&lt;BR /&gt;
&lt;BR /&gt;
XorYisvoid= is for knowing that X or Y was void, but i didn't undestand the behavior of your data.&lt;BR /&gt;
voidValue = for retaining the last value.&lt;BR /&gt;
&lt;BR /&gt;
So you will need a do loop in scl, and some macrovariables. 89 variables is too much for programing with simple if.&lt;BR /&gt;
The next code preteds to collect your variables names, and after using a do loop to fill 1 to 1 the variables, B to A, C to B ...&lt;BR /&gt;
But i have a cuestion, the 89th var have to refill the other 88 if all are null? then you have to start from 89 to 1.&lt;BR /&gt;
&lt;BR /&gt;
First of all you have to make a data step with variables, something like:&lt;BR /&gt;
VarData&lt;BR /&gt;
_N_  VarName&lt;BR /&gt;
1      Name, (we call it A)&lt;BR /&gt;
2      State, (we call it B)&lt;BR /&gt;
3 ...&lt;BR /&gt;
&lt;BR /&gt;
do i=1 to dim (Vardata-1) &lt;BR /&gt;
     call simput('Myindex',i);&lt;BR /&gt;
     submit continue;&lt;BR /&gt;
          data _NULL_;&lt;BR /&gt;
              if _N_ eq &amp;amp;MyIndex Then call simput ('ValueThatIhaveToFill',VarName);&lt;BR /&gt;
              if _N_ eq &amp;amp;MyIndex+1 Then call simput ('ValueThatIhaveToPass',VarName);&lt;BR /&gt;
           run;&lt;BR /&gt;
           data TheDataiHave;&lt;BR /&gt;
              If  &amp;amp;ValueThatIhaveToFill eq '' then &amp;amp;ValueThatIhaveToFill (name, state) = &amp;amp;ValueThatIhaveToPass;&lt;BR /&gt;
           run;&lt;BR /&gt;
     endsubmit;&lt;BR /&gt;
end; (do loop)    &lt;BR /&gt;
     &lt;BR /&gt;
This is not tested but i think it's basically that you want.</description>
      <pubDate>Mon, 15 Mar 2010 08:56:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Imputation/m-p/67476#M14597</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-03-15T08:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Imputation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Imputation/m-p/67477#M14598</link>
      <description>Looks like data I sometimes get from EXCEL.  I assume your starting point is a SAS data set.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data have;&lt;BR /&gt;
   input x $ y @@;&lt;BR /&gt;
   cards;&lt;BR /&gt;
A 2 . 4 . 6 . 8 . 10&lt;BR /&gt;
B 1 . 2 &lt;BR /&gt;
C 1 . 2 . 3 . 4&lt;BR /&gt;
;;;;&lt;BR /&gt;
   run;&lt;BR /&gt;
data need;&lt;BR /&gt;
   if 0 then set have(keep=x);&lt;BR /&gt;
   set have(rename=(x=_x));&lt;BR /&gt;
   x = coalesceC(_x,x);&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
You can drop _X&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
Obs    x    _x     y&lt;BR /&gt;
&lt;BR /&gt;
  1    A    A      2&lt;BR /&gt;
  2    A           4&lt;BR /&gt;
  3    A           6&lt;BR /&gt;
  4    A           8&lt;BR /&gt;
  5    A          10&lt;BR /&gt;
  6    B    B      1&lt;BR /&gt;
  7    B           2&lt;BR /&gt;
  8    C    C      1&lt;BR /&gt;
  9    C           2&lt;BR /&gt;
 10    C           3&lt;BR /&gt;
 11    C           4&lt;BR /&gt;
[/pre]</description>
      <pubDate>Mon, 15 Mar 2010 18:07:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Imputation/m-p/67477#M14598</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-03-15T18:07:13Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Imputation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Imputation/m-p/67478#M14599</link>
      <description>You could do this with a RETAIN statement.  Consider the following:&lt;BR /&gt;
&lt;BR /&gt;
  /* Create some data to test with */&lt;BR /&gt;
data initial;   &lt;BR /&gt;
   input x $ y;&lt;BR /&gt;
datalines;&lt;BR /&gt;
A 2&lt;BR /&gt;
. 4&lt;BR /&gt;
. 6&lt;BR /&gt;
. 8&lt;BR /&gt;
. 10&lt;BR /&gt;
B 1 &lt;BR /&gt;
. 2 &lt;BR /&gt;
C 1 &lt;BR /&gt;
. 2 &lt;BR /&gt;
. 3 &lt;BR /&gt;
. 4&lt;BR /&gt;
;   &lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
  /* Impute missing X values from previous valid values */&lt;BR /&gt;
data imputed;&lt;BR /&gt;
   set initial; &lt;BR /&gt;
   retain LastX " "; &lt;BR /&gt;
   if X="" then X=LastX;&lt;BR /&gt;
   else LastX=X; &lt;BR /&gt;
   drop LastX;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print data=imputed;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/*** Results *******&lt;BR /&gt;
Obs    x     y&lt;BR /&gt;
  1    A     2&lt;BR /&gt;
  2    A     4&lt;BR /&gt;
  3    A     6&lt;BR /&gt;
  4    A     8&lt;BR /&gt;
  5    A    10&lt;BR /&gt;
  6    B     1&lt;BR /&gt;
  7    B     2&lt;BR /&gt;
  8    C     1&lt;BR /&gt;
  9    C     2&lt;BR /&gt;
 10    C     3&lt;BR /&gt;
 11    C     4&lt;BR /&gt;
***********************/</description>
      <pubDate>Wed, 17 Mar 2010 18:19:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Imputation/m-p/67478#M14599</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2010-03-17T18:19:38Z</dc:date>
    </item>
  </channel>
</rss>

