<?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: ADD RECORDS TO MASTER DATA SET BY... in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/373977#M89493</link>
    <description>&lt;P&gt;Sorry. I couldn't understand what you mean.&lt;/P&gt;
&lt;P&gt;Maybe you should start a new session. Let others see your question.&lt;/P&gt;</description>
    <pubDate>Fri, 07 Jul 2017 14:04:42 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2017-07-07T14:04:42Z</dc:date>
    <item>
      <title>ADD RECORDS TO MASTER DATA SET BY...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/371131#M88654</link>
      <description>&lt;P&gt;hi, i need heellpp!&lt;/P&gt;&lt;P&gt;I need to achieve the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data master;
 input id $ x y z;
 datalines;
 1001 340 2 6
 1001 2670 4 8
 1002 990 10 6
 1002 1050 2 1
 1002 887 4 5
 1003 5896 3 2
 ;
run;

data update;
 input id $ x y z;
 datalines;
 1001 340 4 9
 1001 390 2 1
 1003 9900 10 6
 1003 1050 2 1
 1004 887 4 5
 1009 5896 3 2
 ;
run;

data want;**-----&amp;gt; add (or update) records by id (if id are present in master. i.e id=1004 or 1009 dont interest me); 
 input id $ x y z;
 datalines;
 1001 340 2 6
 1001 2670 4 8
 1001 340 4 9
 1001 390 2 1 
 1002 990 10 6
 1002 1050 2 1
 1002 887 4 5
 1003 5896 3 2
 1003 9900 10 6
 1003 1050 2 1
 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thankss!&lt;/P&gt;&lt;P&gt;Alan&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 04:07:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/371131#M88654</guid>
      <dc:creator>alan_maxs</dc:creator>
      <dc:date>2017-06-28T04:07:46Z</dc:date>
    </item>
    <item>
      <title>Re: ADD RECORDS TO MASTER DATA SET BY...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/371132#M88655</link>
      <description>&lt;P&gt;something like this . I just changed your table name from update to updated&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
create table temp_table as 
select * from updated a
where exists(select * from master b
where a.id =b.id);
insert into master
select * from temp_table;
quit;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table temp_table as &lt;BR /&gt;select * from updated &lt;BR /&gt;where id in(select id from master);&lt;BR /&gt;insert into master&lt;BR /&gt;select * from temp_table;&lt;BR /&gt;quit;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 04:35:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/371132#M88655</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2017-06-28T04:35:37Z</dc:date>
    </item>
    <item>
      <title>Re: ADD RECORDS TO MASTER DATA SET BY...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/371174#M88663</link>
      <description>&lt;P&gt;Couple of issues with what you post, dont call a dataste "update", and also specify what the by groups are here as x y z is non descriptive. &amp;nbsp;I assumed that as ID has multiple rows that X is the other grouping variable. &amp;nbsp;SAS provides the update statement in datastep specifically for these master/transaction processes, docs here:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/basess/68381/HTML/default/viewer.htm#n0s3jm3mkzvz5qn1mri4483ouhzi.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/basess/68381/HTML/default/viewer.htm#n0s3jm3mkzvz5qn1mri4483ouhzi.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And for your example:&lt;/P&gt;
&lt;PRE&gt;data master;
 input id $ x y z;
 datalines;
 1001 340 2 6
 1001 2670 4 8
 1002 990 10 6
 1002 1050 2 1
 1002 887 4 5
 1003 5896 3 2
 ;
run;

data new_data;
 input id $ x y z;
 datalines;
 1001 340 4 9
 1001 390 2 1
 1003 9900 10 6
 1003 1050 2 1
 1004 887 4 5
 1009 5896 3 2
 ;
run;

proc sort data=master;
  by id x;
run;

proc sort data=new_data;
  by id x;
run;
  
data want;
  update master new_data;
  by id x;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Jun 2017 08:41:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/371174#M88663</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-28T08:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: ADD RECORDS TO MASTER DATA SET BY...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/371245#M88671</link>
      <description>&lt;P&gt;Here's a DATA step approach that assumes both data sets are sorted:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set master (in=in1) update;&lt;/P&gt;
&lt;P&gt;by id;&lt;/P&gt;
&lt;P&gt;if first.id then keep_flag = in1;&lt;/P&gt;
&lt;P&gt;retain keep_flag;&lt;/P&gt;
&lt;P&gt;if keep_flag=1;&lt;/P&gt;
&lt;P&gt;drop keep_flag;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In SAS terminology, we would usually call this interleaving (rather than merging or updating).&amp;nbsp; You have the added twist of wanting to eliminate ID values that are not in the master data set.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 12:21:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/371245#M88671</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-06-28T12:21:36Z</dc:date>
    </item>
    <item>
      <title>Re: ADD RECORDS TO MASTER DATA SET BY...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/371263#M88676</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data master;
 input id $ x y z;
 datalines;
 1001 340 2 6
 1001 2670 4 8
 1002 990 10 6
 1002 1050 2 1
 1002 887 4 5
 1003 5896 3 2
 ;
run;

data new_data;
 input id $ x y z;
 datalines;
 1001 340 4 9
 1001 390 2 1
 1003 9900 10 6
 1003 1050 2 1
 1004 887 4 5
 1009 5896 3 2
 ;
run;
proc sql;
create table want as
 select *
  from master
union all corr
 select *
  from new_data
   where id in (select id from master)
order by id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Jun 2017 12:49:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/371263#M88676</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-06-28T12:49:42Z</dc:date>
    </item>
    <item>
      <title>Re: ADD RECORDS TO MASTER DATA SET BY...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/372860#M89185</link>
      <description>thanks!!&lt;BR /&gt;I sorry for the terminology, i'm new!</description>
      <pubDate>Mon, 03 Jul 2017 21:24:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/372860#M89185</guid>
      <dc:creator>alan_maxs</dc:creator>
      <dc:date>2017-07-03T21:24:39Z</dc:date>
    </item>
    <item>
      <title>Re: ADD RECORDS TO MASTER DATA SET BY...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/372861#M89186</link>
      <description>thanks! its works! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Mon, 03 Jul 2017 21:25:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/372861#M89186</guid>
      <dc:creator>alan_maxs</dc:creator>
      <dc:date>2017-07-03T21:25:16Z</dc:date>
    </item>
    <item>
      <title>Re: ADD RECORDS TO MASTER DATA SET BY...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/372863#M89187</link>
      <description>&lt;P&gt;Hi Ksharp, thank you very much for your reply, its works!&lt;/P&gt;&lt;P&gt;Can I ask you another question?&lt;/P&gt;&lt;P&gt;I have the following situation:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input id $ weight1 weight2 age year $ group $;
 datalines;
 1001 340 330 35.7 1990 2
 1001 267 289 35.7 1988 2
 1001 300 297 35.7 1989 2  
 1002 450 438 33.2 1995 1
 1002 299 279 33.2 1993 1
 1002 390 385 33.2 1994 1
 1003 519 512 39.5 2000 4
 1003 450 443 39.5 1998 4
 1003 329 316 39.5 1997 4
 1003 310 301 39.5 1995 4
 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;I need to generate a new dataset ("want") which adds &lt;U&gt;an observation&amp;nbsp; by id&lt;/U&gt; putting zeroes (0) to two variables ("weight1" &amp;amp; "weight2") and retaining the original values ​​of the others ("age", "year" &amp;amp; "group").&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;like as:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 input id $ weight1 weight2 age year $ group $;
 datalines;
 1001 0 0 35.7 1990 2
 1001 340 330 35.7 1990 2
 1001 267 289 35.7 1988 2
 1001 300 297 35.7 1989 2
 1002 0 0 33.2 1995 1
 1002 450 438 33.2 1995 1
 1002 299 279 33.2 1993 1
 1002 390 385 33.2 1994 1
 1003 0 0 39.5 2000 4
 1003 519 512 39.5 2000 4
 1003 450 443 39.5 1998 4
 1003 329 316 39.5 1997 4
 1003 310 301 39.5 1995 4
 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;it is understood?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jul 2017 21:32:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/372863#M89187</guid>
      <dc:creator>alan_maxs</dc:creator>
      <dc:date>2017-07-03T21:32:51Z</dc:date>
    </item>
    <item>
      <title>Re: ADD RECORDS TO MASTER DATA SET BY...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/372978#M89203</link>
      <description>&lt;P&gt;OK. Here is .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input id $ weight1 weight2 age year $ group $;
 datalines;
 1001 340 330 35.7 1990 2
 1001 267 289 35.7 1988 2
 1001 300 297 35.7 1989 2  
 1002 450 438 33.2 1995 1
 1002 299 279 33.2 1993 1
 1002 390 385 33.2 1994 1
 1003 519 512 39.5 2000 4
 1003 450 443 39.5 1998 4
 1003 329 316 39.5 1997 4
 1003 310 301 39.5 1995 4
 ;
run;
data want;
 set have;
 by id;
 if first.id then do;
  w1=weight1;w2=weight2;
  weight1=0;weight2=0;output;
  weight1=w1;weight2=w2;output;
 end;
 else output;
 drop w1 w2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Jul 2017 13:07:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/372978#M89203</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-07-04T13:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: ADD RECORDS TO MASTER DATA SET BY...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/373070#M89240</link>
      <description>&lt;P&gt;Thanks Ksharp!!&lt;/P&gt;&lt;P&gt;Another query please, is there any function in SAS that allows to invoke "all variables"?&lt;/P&gt;&lt;P&gt;For example: If "all variables" ne weight1 or weight2 then "all variables" = .;&lt;BR /&gt;Do you understand what I want to do?&lt;/P&gt;&lt;P&gt;In my situation above (if first.id then do), if I wanted to put all other variables missing except for weight1 or weight2 (latter = 0) ...&lt;BR /&gt;because in my original file I have many variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks, again!&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jul 2017 18:02:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/373070#M89240</guid>
      <dc:creator>alan_maxs</dc:creator>
      <dc:date>2017-07-04T18:02:10Z</dc:date>
    </item>
    <item>
      <title>Re: ADD RECORDS TO MASTER DATA SET BY...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/373240#M89290</link>
      <description>&lt;P&gt;No . There is no such function . But you can use ARRAY to get what you want .&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2017 12:41:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/373240#M89290</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-07-05T12:41:09Z</dc:date>
    </item>
    <item>
      <title>Re: ADD RECORDS TO MASTER DATA SET BY...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/373722#M89410</link>
      <description>&lt;P&gt;Ok.&lt;/P&gt;&lt;P&gt;I ask one last help:&lt;/P&gt;&lt;P&gt;I'm building a macro that allows you to keep observations for 2 conditions:&lt;BR /&gt;1- if the frequencies of &amp;amp;contgroup are greater than or equal to 3;&lt;BR /&gt;2- if the frequencies of &amp;amp;sire are greater than or equal to 3;&lt;/P&gt;&lt;P&gt;The complex thing is that eliminating observations by 1- changes the frequencies to 2-, and vice versa. It is understood?&lt;/P&gt;&lt;P&gt;Here is an example of my data file:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input id $ sire $ contgroup $;
 datalines;
9914089	9613073	81999	
9914096	9512799	81999	
9914108	100671	81999	
9914115	100690	81999	
9914119	100690	81999	
9914124	100689	81999	
9914130	9613166	81999	
9914136	9613048	81999	
9914137	100671	91999	
9914148	9512799	91999	
9914158	9613166	91999	
9914163	100671	91999	
9914164	9512782	91999
;
run;	&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have tried several ways but I always have the same problem, deleting/retaining observations for one of the conditions, change the frequencies of the other variable.&lt;/P&gt;&lt;P&gt;How could the macro do?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Alan&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2017 17:31:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/373722#M89410</guid>
      <dc:creator>alan_maxs</dc:creator>
      <dc:date>2017-07-06T17:31:49Z</dc:date>
    </item>
    <item>
      <title>Re: ADD RECORDS TO MASTER DATA SET BY...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/373977#M89493</link>
      <description>&lt;P&gt;Sorry. I couldn't understand what you mean.&lt;/P&gt;
&lt;P&gt;Maybe you should start a new session. Let others see your question.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2017 14:04:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/373977#M89493</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-07-07T14:04:42Z</dc:date>
    </item>
    <item>
      <title>Re: ADD RECORDS TO MASTER DATA SET BY...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/374059#M89507</link>
      <description>Ok.&lt;BR /&gt;Here: &lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/delete-retein-observations-by-frequency-n-of-variables/m-p/374057#M89506" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/delete-retein-observations-by-frequency-n-of-variables/m-p/374057#M89506&lt;/A&gt;</description>
      <pubDate>Fri, 07 Jul 2017 18:25:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ADD-RECORDS-TO-MASTER-DATA-SET-BY/m-p/374059#M89507</guid>
      <dc:creator>alan_maxs</dc:creator>
      <dc:date>2017-07-07T18:25:28Z</dc:date>
    </item>
  </channel>
</rss>

