<?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: Update one dataset with same value for selected field for only ids in another dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Update-one-dataset-with-same-value-for-selected-field-for-only/m-p/809790#M319346</link>
    <description>&lt;P&gt;Thank you everyone!&lt;/P&gt;</description>
    <pubDate>Mon, 25 Apr 2022 22:30:34 GMT</pubDate>
    <dc:creator>jcis7</dc:creator>
    <dc:date>2022-04-25T22:30:34Z</dc:date>
    <item>
      <title>Update one dataset with same value for selected field for only ids in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-one-dataset-with-same-value-for-selected-field-for-only/m-p/808449#M318785</link>
      <description>&lt;P&gt;G'day!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Appreciate any help you can give.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've two datasets with the following names and content:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&amp;nbsp;'idsdataset' that has the variable name 'id' and 'type'&lt;/LI&gt;
&lt;LI&gt;'toupdatedataset' that has the variable names 'id', 'type', and 'status'&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like to update the field 'status' in the dataset 'toupdatedataset' with the value 'N' for all of the observations in the 'idsdataset' dataset based on 'id' in both datasets.&lt;/P&gt;
&lt;P&gt;The outcome I'm looking for is listed in the dataset 'updateddataset'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I update 'status' field without needing to enter each 'id' individually?&amp;nbsp; Thank you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data idsdataset;
   input id $ type$;
   datalines;
1234567 Pub
1245678 Pub
;
data toupdatedataset;
   input id $ type $ status $;
   datalines;
1234567 Pub .
1245678  Pub . 
2349878 Pri N
3948573 Priv Y
;

data updateddataset;
  set toupdate;
if id in ('1234567' , '1245678') then status='N';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Apr 2022 22:28:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-one-dataset-with-same-value-for-selected-field-for-only/m-p/808449#M318785</guid>
      <dc:creator>jcis7</dc:creator>
      <dc:date>2022-04-18T22:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: Update one dataset with same value for selected field for only ids in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-one-dataset-with-same-value-for-selected-field-for-only/m-p/808451#M318787</link>
      <description>&lt;P&gt;Here is one way:&lt;/P&gt;
&lt;PRE&gt;data updateddataset;
  merge toupdatedataset (in=Inleft) 
        idsdataset      (in=Inright)
  ;
  by id;
  if missing(status) and inleft and inright then Status='N';
run;&lt;/PRE&gt;
&lt;P&gt;If the data sets on the Merge statement are not sorted by ID then you should sort them prior to merge.&lt;/P&gt;
&lt;P&gt;The dataset option IN= creates a temporary variable (means that variable is not written to the data) that is a 1/0 (True/False) value. So you can test if a record is coming from both data sets. I am &lt;STRONG&gt;assuming&lt;/STRONG&gt; that you want to change the missing status values if present only. If that is not actually the case then remove the "missing(status) and" part of the If.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please make sure that you spell your data sets consistently. I could not tell if there was supposed to be a 4th data set named Toupdate that was actually different than Toupdatedataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Warning about the above solution: If your ISDATASET contains ID and TYPE not already in the TOUPDATEDATASET they will be added (and status will be missing). If this might occur and you do not want it to then you would subset the data with an "IF inleft;"&lt;/P&gt;</description>
      <pubDate>Mon, 18 Apr 2022 23:40:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-one-dataset-with-same-value-for-selected-field-for-only/m-p/808451#M318787</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-04-18T23:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: Update one dataset with same value for selected field for only ids in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-one-dataset-with-same-value-for-selected-field-for-only/m-p/808453#M318789</link>
      <description>&lt;P&gt;I like Ballard's way better (mine is the long way around) but I'll post this anyway:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

*populate the missings;
proc sql;
create table populatedidsdataset as 
select a.id, a.type,
case
	when missing(status) then 'N'
	else status 
end as status
from
toupdatedataset a inner join idsdataset b
on a.id = b.id and a.type = b.type;
quit; 

* keep your good ones;
data parsed;
set toupdatedataset;
if not missing(status);
run;

* smash your populated ones and good ones back together;
data want;
	merge populatedidsdataset parsed;
	by id; 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Apr 2022 22:59:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-one-dataset-with-same-value-for-selected-field-for-only/m-p/808453#M318789</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2022-04-18T22:59:59Z</dc:date>
    </item>
    <item>
      <title>Re: Update one dataset with same value for selected field for only ids in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-one-dataset-with-same-value-for-selected-field-for-only/m-p/808454#M318790</link>
      <description>&lt;P&gt;Thanks for catching that I didn't name the dataset in the set statement in the&amp;nbsp; 'data updateddataset' statement 'toupdatedataset' and instead named it 'toupdate'.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Apr 2022 23:03:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-one-dataset-with-same-value-for-selected-field-for-only/m-p/808454#M318790</guid>
      <dc:creator>jcis7</dc:creator>
      <dc:date>2022-04-18T23:03:45Z</dc:date>
    </item>
    <item>
      <title>Re: Update one dataset with same value for selected field for only ids in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-one-dataset-with-same-value-for-selected-field-for-only/m-p/808456#M318791</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/40498"&gt;@jcis7&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;As I understand from your post, the requirement is that if the id's in both the datasets ( idsdataset and toupdatedataset ) match&amp;nbsp; then set the values of Status to N&amp;nbsp; &amp;nbsp;in the updated dataset&amp;nbsp;.&amp;nbsp; Thus I would go by what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;has given with a minor change. My code would be as follows&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data idsdataset;
   input id $ type$;
   datalines;
1234567 Pub
1245678 Pub
;
data toupdatedataset;
   input id $ type $ status $;
   datalines;
1234567 Pub .
1245678  Pub . 
2349878 Pri N
3948573 Priv Y
;
proc sort data=idsdataset;
by id;
run;
proc sort data=toupdatedataset;
by id;
run;
data updateddataset;
  merge toupdatedataset (in=Inleft) 
        idsdataset      (in=Inright)
  ;
  by id;
  if inleft and inright then Status='N';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Apr 2022 23:25:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-one-dataset-with-same-value-for-selected-field-for-only/m-p/808456#M318791</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2022-04-18T23:25:56Z</dc:date>
    </item>
    <item>
      <title>Re: Update one dataset with same value for selected field for only ids in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-one-dataset-with-same-value-for-selected-field-for-only/m-p/809790#M319346</link>
      <description>&lt;P&gt;Thank you everyone!&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 22:30:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-one-dataset-with-same-value-for-selected-field-for-only/m-p/809790#M319346</guid>
      <dc:creator>jcis7</dc:creator>
      <dc:date>2022-04-25T22:30:34Z</dc:date>
    </item>
  </channel>
</rss>

