<?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 update a data set with more records in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-update-a-data-set-with-more-records/m-p/665709#M199098</link>
    <description>&lt;P&gt;Here is a datastep solution:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have; 
  by id trt visit;
  if first.visit then 
    _extptnum=1;
  do extptnum=_extptnum to extptnum;
    output;
    end;
  _extptnum=extptnum; /* extptnum is now original value +1 */
  if last.visit;
  do extptnum=extptnum to 4;
    output;
    end;
  drop _extptnum;
  retain _extptnum;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that this solution, unlike the one by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;, also assigns values to other variables:&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;If it is not the last visit, holes will be filled out using data from the next higher extptnum value&lt;/LI&gt;
&lt;LI&gt;If it is the last visit, the values will be used to fill out up to extptnum=4&lt;/LI&gt;
&lt;/UL&gt;</description>
    <pubDate>Mon, 29 Jun 2020 06:24:14 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2020-06-29T06:24:14Z</dc:date>
    <item>
      <title>how to update a data set with more records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-update-a-data-set-with-more-records/m-p/665565#M199032</link>
      <description>&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to add more records to data set by &lt;FONT color="#FF6600"&gt;id,trt,visit&lt;/FONT&gt; if there are any missing records. Please suggest.&lt;/P&gt;
&lt;P&gt;I need to add the records in red. For each,&amp;nbsp;&lt;FONT color="#FF6600"&gt;id,trt,visit&lt;/FONT&gt;&amp;nbsp; i ineed to have four records with extptnum 1 to 4&lt;/P&gt;
&lt;P&gt;output&amp;nbsp; needed&lt;/P&gt;
&lt;P&gt;1 p CYCLE1 1&lt;BR /&gt;1 p CYCLE1 2&lt;BR /&gt;1 p CYCLE1 3&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;1 p CYCLE1 4&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;1 p CYCLE2 1&lt;/FONT&gt;&lt;BR /&gt;1 p CYCLE2 2&lt;BR /&gt;1 p CYCLE2 3&lt;BR /&gt;1 p CYCLE2 4&lt;BR /&gt;1 p CYCLE3 1&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;1 p CYCLE3 2&lt;/FONT&gt;&lt;BR /&gt;1 p CYCLE3 3&lt;BR /&gt;1 p CYCLE3 4&lt;BR /&gt;1 p CYCLE4 1&lt;BR /&gt;1 p CYCLE4 2&lt;BR /&gt;1 p CYCLE4 3&lt;BR /&gt;1 p CYCLE4 4&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id trt $ visit $ extptnum;
datalines;
1 p CYCLE1 1
1 p CYCLE1 2
1 p CYCLE1 3
1 p CYCLE2 2
1 p CYCLE2 3
1 p CYCLE2 4
1 p CYCLE3 1
1 p CYCLE3 3
1 p CYCLE3 4
1 p CYCLE4 1
1 p CYCLE4 2
1 p CYCLE4 3
1 p CYCLE4 4
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 27 Jun 2020 20:53:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-update-a-data-set-with-more-records/m-p/665565#M199032</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2020-06-27T20:53:36Z</dc:date>
    </item>
    <item>
      <title>Re: how to update a data set with more records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-update-a-data-set-with-more-records/m-p/665571#M199034</link>
      <description>&lt;P&gt;Try next not tested code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  create table tmp1 as
   select distinct id, trt, visit
   from have;
quit;
data tmp2;
 set tmp1;
     do extptnum=1 to 4; output; end;
run;
data want;
 merge have tmp2;
  by id trt visit;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 27 Jun 2020 21:31:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-update-a-data-set-with-more-records/m-p/665571#M199034</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-06-27T21:31:35Z</dc:date>
    </item>
    <item>
      <title>Re: how to update a data set with more records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-update-a-data-set-with-more-records/m-p/665572#M199035</link>
      <description>&lt;P&gt;Use a cross join to generate all needed combinations :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id trt $ visit $ extptnum other $;
datalines;
1 p CYCLE1 1 a
1 p CYCLE1 2 b 
1 p CYCLE1 3 c
1 p CYCLE2 2 d 
1 p CYCLE2 3 e 
1 p CYCLE2 4 f
1 p CYCLE3 1 g
1 p CYCLE3 3 h
1 p CYCLE3 4 i
1 p CYCLE4 1 j
1 p CYCLE4 2 k
1 p CYCLE4 3 l
1 p CYCLE4 4 m
;

proc sql;
select 
    a.*, 
    b.*, 
    c.other
from
    (select unique id, trt, visit from have) as a cross join
    (select unique extptnum from have) as b left join 
    have as c on a.id=c.id and a.trt=c.trt and a.visit=c.visit and b.extptnum=c.extptnum;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;id 	trt 	visit 	extptnum 	other
1 	p 	CYCLE1 	1 	a
1 	p 	CYCLE1 	2 	b
1 	p 	CYCLE1 	3 	c
1 	p 	CYCLE1 	4 	 
1 	p 	CYCLE2 	1 	 
1 	p 	CYCLE2 	2 	d
1 	p 	CYCLE2 	3 	e
1 	p 	CYCLE2 	4 	f
1 	p 	CYCLE3 	1 	g
1 	p 	CYCLE3 	2 	 
1 	p 	CYCLE3 	3 	h
1 	p 	CYCLE3 	4 	i
1 	p 	CYCLE4 	1 	j
1 	p 	CYCLE4 	2 	k
1 	p 	CYCLE4 	3 	l
1 	p 	CYCLE4 	4 	m&lt;/PRE&gt;</description>
      <pubDate>Sat, 27 Jun 2020 22:07:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-update-a-data-set-with-more-records/m-p/665572#M199035</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-06-27T22:07:42Z</dc:date>
    </item>
    <item>
      <title>Re: how to update a data set with more records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-update-a-data-set-with-more-records/m-p/665594#M199050</link>
      <description>Just use the SPARSE option on PROC FREQ.&lt;BR /&gt;&lt;BR /&gt;proc freq data=have;&lt;BR /&gt;table id*trt*visit*pNum / sparse out=want;&lt;BR /&gt;run;</description>
      <pubDate>Sun, 28 Jun 2020 02:03:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-update-a-data-set-with-more-records/m-p/665594#M199050</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-28T02:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: how to update a data set with more records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-update-a-data-set-with-more-records/m-p/665709#M199098</link>
      <description>&lt;P&gt;Here is a datastep solution:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have; 
  by id trt visit;
  if first.visit then 
    _extptnum=1;
  do extptnum=_extptnum to extptnum;
    output;
    end;
  _extptnum=extptnum; /* extptnum is now original value +1 */
  if last.visit;
  do extptnum=extptnum to 4;
    output;
    end;
  drop _extptnum;
  retain _extptnum;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that this solution, unlike the one by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;, also assigns values to other variables:&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;If it is not the last visit, holes will be filled out using data from the next higher extptnum value&lt;/LI&gt;
&lt;LI&gt;If it is the last visit, the values will be used to fill out up to extptnum=4&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Mon, 29 Jun 2020 06:24:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-update-a-data-set-with-more-records/m-p/665709#M199098</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-06-29T06:24:14Z</dc:date>
    </item>
  </channel>
</rss>

