<?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: Filling in gaps in sequential data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-gaps-in-sequential-data/m-p/30476#M5816</link>
    <description>Hello Enginemane44,&lt;BR /&gt;
&lt;BR /&gt;
It looks like your input dataset should contain an additional variable, say ID, to distinguish two sets of data. Anyway, to solve the problem for the first set of questions you can use the following code:&lt;BR /&gt;
&lt;BR /&gt;
data a;&lt;BR /&gt;
input QNUM Rating;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 3.0&lt;BR /&gt;
2 2.9&lt;BR /&gt;
3 10.0&lt;BR /&gt;
5 7.7 &lt;BR /&gt;
6 8.9&lt;BR /&gt;
7 9.1&lt;BR /&gt;
9 10.0&lt;BR /&gt;
10 7.6&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
data t;&lt;BR /&gt;
  do qnum=1 to 10;&lt;BR /&gt;
  output;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
data r;&lt;BR /&gt;
  merge a(in=a) t(in=t);&lt;BR /&gt;
  if a and t then output;&lt;BR /&gt;
  if not a and t then output; &lt;BR /&gt;
   by qnum;   &lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Sincerely,</description>
    <pubDate>Mon, 08 Nov 2010 22:14:00 GMT</pubDate>
    <dc:creator>SPR</dc:creator>
    <dc:date>2010-11-08T22:14:00Z</dc:date>
    <item>
      <title>Filling in gaps in sequential data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-gaps-in-sequential-data/m-p/30475#M5815</link>
      <description>SAS-L'ers&lt;BR /&gt;
I have an interesting data step problem which should be easy, but whose solution is escaping me.  Essentially, I have a data set with gaps in it :&lt;BR /&gt;
&lt;BR /&gt;
QNUM  Rating&lt;BR /&gt;
1          3.0&lt;BR /&gt;
2          2.9&lt;BR /&gt;
3         10.0&lt;BR /&gt;
5          7.7 &lt;BR /&gt;
6          8.9&lt;BR /&gt;
7          9.1&lt;BR /&gt;
9         10.0&lt;BR /&gt;
10         7.6&lt;BR /&gt;
1           9.8&lt;BR /&gt;
2           7.0&lt;BR /&gt;
3           6.3&lt;BR /&gt;
4           4.9&lt;BR /&gt;
5           5.5&lt;BR /&gt;
7           6.3&lt;BR /&gt;
8           8.9&lt;BR /&gt;
9           9.9&lt;BR /&gt;
10         7.9&lt;BR /&gt;
etc.&lt;BR /&gt;
There are ten questions total.  What I'm looking for is code to 'fill in the gaps' with ratings set to missing :&lt;BR /&gt;
QNUM  Rating&lt;BR /&gt;
1          3.0&lt;BR /&gt;
2          2.9&lt;BR /&gt;
3         10.0&lt;BR /&gt;
4          .     &amp;lt;-- filled in missing Q4&lt;BR /&gt;
5          7.7 &lt;BR /&gt;
6          8.9&lt;BR /&gt;
7          9.1&lt;BR /&gt;
8           .    &amp;lt;-- filled in missing Q8&lt;BR /&gt;
9         10.0&lt;BR /&gt;
10         7.6&lt;BR /&gt;
&lt;BR /&gt;
I've tried all kinds of counters and flags/DO loops, etc. to no avail.  Anybody have any hints ?&lt;BR /&gt;
&lt;BR /&gt;
Barry Walton</description>
      <pubDate>Mon, 08 Nov 2010 20:59:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-in-gaps-in-sequential-data/m-p/30475#M5815</guid>
      <dc:creator>enginemane44</dc:creator>
      <dc:date>2010-11-08T20:59:15Z</dc:date>
    </item>
    <item>
      <title>Re: Filling in gaps in sequential data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-gaps-in-sequential-data/m-p/30476#M5816</link>
      <description>Hello Enginemane44,&lt;BR /&gt;
&lt;BR /&gt;
It looks like your input dataset should contain an additional variable, say ID, to distinguish two sets of data. Anyway, to solve the problem for the first set of questions you can use the following code:&lt;BR /&gt;
&lt;BR /&gt;
data a;&lt;BR /&gt;
input QNUM Rating;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 3.0&lt;BR /&gt;
2 2.9&lt;BR /&gt;
3 10.0&lt;BR /&gt;
5 7.7 &lt;BR /&gt;
6 8.9&lt;BR /&gt;
7 9.1&lt;BR /&gt;
9 10.0&lt;BR /&gt;
10 7.6&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
data t;&lt;BR /&gt;
  do qnum=1 to 10;&lt;BR /&gt;
  output;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
data r;&lt;BR /&gt;
  merge a(in=a) t(in=t);&lt;BR /&gt;
  if a and t then output;&lt;BR /&gt;
  if not a and t then output; &lt;BR /&gt;
   by qnum;   &lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Sincerely,</description>
      <pubDate>Mon, 08 Nov 2010 22:14:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-in-gaps-in-sequential-data/m-p/30476#M5816</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2010-11-08T22:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: Filling in gaps in sequential data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-gaps-in-sequential-data/m-p/30477#M5817</link>
      <description>If the data are not strictly sequential or if the list of possible QNUMs is not well specified, a double transpose using QNUM as the ID variable will also fill in the gaps.</description>
      <pubDate>Tue, 09 Nov 2010 02:17:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-in-gaps-in-sequential-data/m-p/30477#M5817</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2010-11-09T02:17:39Z</dc:date>
    </item>
    <item>
      <title>Re: Filling in gaps in sequential data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-gaps-in-sequential-data/m-p/30478#M5818</link>
      <description>Hi.I think Patrick can do it very well.&lt;BR /&gt;
[pre]&lt;BR /&gt;
data temp;&lt;BR /&gt;
 input num rate;;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 3.0&lt;BR /&gt;
2 2.9&lt;BR /&gt;
3 10.0&lt;BR /&gt;
5 7.7&lt;BR /&gt;
6 8.9&lt;BR /&gt;
7 9.1&lt;BR /&gt;
9 10.0&lt;BR /&gt;
10 7.6&lt;BR /&gt;
1 9.8&lt;BR /&gt;
2 7.0&lt;BR /&gt;
3 6.3&lt;BR /&gt;
4 4.9&lt;BR /&gt;
5 5.5&lt;BR /&gt;
7 6.3&lt;BR /&gt;
8 8.9&lt;BR /&gt;
9 9.9&lt;BR /&gt;
10 7.9&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
data result(drop=num rate);&lt;BR /&gt;
 set temp;&lt;BR /&gt;
 qnum+1;&lt;BR /&gt;
 do while(qnum lt num) ;&lt;BR /&gt;
    call missing(rating);&lt;BR /&gt;
	output;&lt;BR /&gt;
	qnum+1;&lt;BR /&gt;
 end;&lt;BR /&gt;
 rating=rate;&lt;BR /&gt;
 output;&lt;BR /&gt;
 if qnum eq 10 then qnum=0;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print noobs;run;&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Ksharp</description>
      <pubDate>Tue, 09 Nov 2010 09:18:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-in-gaps-in-sequential-data/m-p/30478#M5818</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-11-09T09:18:23Z</dc:date>
    </item>
    <item>
      <title>Re: Filling in gaps in sequential data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-gaps-in-sequential-data/m-p/30479#M5819</link>
      <description>Hi all,&lt;BR /&gt;
Ksharp was right on - I tried the code and it worked perfectly.  Thanks to Ksharp and all the others who responded.  I suspected a merge may be an alternate way to do it, but I wasn't sure what to merge the data with.&lt;BR /&gt;
Barry Walton</description>
      <pubDate>Tue, 09 Nov 2010 15:30:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-in-gaps-in-sequential-data/m-p/30479#M5819</guid>
      <dc:creator>enginemane44</dc:creator>
      <dc:date>2010-11-09T15:30:14Z</dc:date>
    </item>
  </channel>
</rss>

