<?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 Self Update a Column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Self-Update-a-Column/m-p/483581#M125412</link>
    <description>&lt;P&gt;Is there an easy way to do something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
	create table TEMP_PELL_ELIGIBLE as
	select distinct person_uid, degree_level
	from STU_GRAD_RETEN 
	where PELL_ELIGIBLE = 'Pell Eligible';
quit;

proc sort data= STU_GRAD_RETEN;
	by person_uid degree_level;
run;

proc sort data= TEMP_PELL_ELIGIBLE;
	by person_uid degree_level;
run;

data STU_GRAD_RETEN; merge STU_GRAD_RETEN (drop= PELL_ELIGIBLE) TEMP_PELL_ELIGIBLE;
	by person_uid degree_level;
	length PELL_ELIGIBLE $50.;
	if PELL_ELIGIBLE ne 'Pell Eligible' then 'Not Pell Eligible';
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 02 Aug 2018 20:40:52 GMT</pubDate>
    <dc:creator>DavidPhillips2</dc:creator>
    <dc:date>2018-08-02T20:40:52Z</dc:date>
    <item>
      <title>Self Update a Column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Self-Update-a-Column/m-p/483581#M125412</link>
      <description>&lt;P&gt;Is there an easy way to do something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
	create table TEMP_PELL_ELIGIBLE as
	select distinct person_uid, degree_level
	from STU_GRAD_RETEN 
	where PELL_ELIGIBLE = 'Pell Eligible';
quit;

proc sort data= STU_GRAD_RETEN;
	by person_uid degree_level;
run;

proc sort data= TEMP_PELL_ELIGIBLE;
	by person_uid degree_level;
run;

data STU_GRAD_RETEN; merge STU_GRAD_RETEN (drop= PELL_ELIGIBLE) TEMP_PELL_ELIGIBLE;
	by person_uid degree_level;
	length PELL_ELIGIBLE $50.;
	if PELL_ELIGIBLE ne 'Pell Eligible' then 'Not Pell Eligible';
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Aug 2018 20:40:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Self-Update-a-Column/m-p/483581#M125412</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2018-08-02T20:40:52Z</dc:date>
    </item>
    <item>
      <title>Re: Self Update a Column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Self-Update-a-Column/m-p/483597#M125416</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5059"&gt;@DavidPhillips2&lt;/a&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not sure how to specify ELSE with update but you can do it in two shots: (1) update the matching rows with "Pell Eligible" (just "E" in the sample below) and (2) update the remaining non-matching rows with "Not Pell Eligible" (just "N" below). E.g.:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp ;                                                        
  input uid ;                                                      
  cards ;                                                          
0                                                                  
2                                                                  
4                                                                  
5                                                                  
;                                                                  
run ;                                                              
                                                                   
data reten ;                                                       
  input uid elig $1. ;                                             
  cards ;                                                          
1 X                                                                
2 X                                                                
2 X                                                                
3 X                                                                
3 X                                                                
4 X                                                                
5 X                                                                
5 X                                                                
;                                                                  
run ;                                                              
                                                                   
proc sql ;                                                         
  update reten set elig = "E" where uid in (select uid from temp) ;
  update reten set elig = "N" where elig ne "E" ;                  
quit ;      &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Better SQL heads will surely tell you how to do it better. Alternatively, you can use a hash table to rewrite the master data set or create a new one and keep the original:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*data newreten ;&lt;BR /&gt;data reten ;                        
  if _n_ = 1 then do ;              
    dcl hash u (dataset:"temp") ;   
    u.definekey ("uid") ;           
    u.definedone () ;               
  end ;                             
  set reten ;                       
  if u.check() = 0 then elig = "E" ;
  else elig = "N" ;                 
run ;                               &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Aug 2018 21:21:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Self-Update-a-Column/m-p/483597#M125416</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2018-08-02T21:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: Self Update a Column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Self-Update-a-Column/m-p/483635#M125439</link>
      <description>&lt;P&gt;you can do either by update statement or by doing a left join and creating a table&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/* by update method*/
proc sql ;                                                         
  update reten a
  set elig =  case when a.uid in (select uid from temp) 
  then 'E' else 'N' end;                  
quit ; 

/* by creating new table*/

proc sql;
create table new as 
select a.uid, 
 case when a.uid = b.uid then 'E'
 else 'N'
 end as elig
from reten a
left join
temp b
on a.uid = b.uid;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Aug 2018 01:08:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Self-Update-a-Column/m-p/483635#M125439</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-08-03T01:08:42Z</dc:date>
    </item>
    <item>
      <title>Re: Self Update a Column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Self-Update-a-Column/m-p/483637#M125440</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37783"&gt;@kiranv_&lt;/a&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That's it! I knew some SQL head would straighten me out on conditional UPDATE. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 01:13:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Self-Update-a-Column/m-p/483637#M125440</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2018-08-03T01:13:06Z</dc:date>
    </item>
    <item>
      <title>Re: Self Update a Column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Self-Update-a-Column/m-p/483638#M125441</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp;This is too kind of you. I just started&amp;nbsp; hash learning/journey from this Monday after getting kindle version of your book. thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 01:32:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Self-Update-a-Column/m-p/483638#M125441</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-08-03T01:32:37Z</dc:date>
    </item>
    <item>
      <title>Re: Self Update a Column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Self-Update-a-Column/m-p/483641#M125442</link>
      <description>&lt;P&gt;Ah, in this case the pleasure is all mine. And, I'm sure, Don's as well. Thanks for reading it: We definitely didn't write it just to let it gather dust on a bookshelf.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 02:10:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Self-Update-a-Column/m-p/483641#M125442</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2018-08-03T02:10:10Z</dc:date>
    </item>
    <item>
      <title>Re: Self Update a Column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Self-Update-a-Column/m-p/483667#M125455</link>
      <description>&lt;P&gt;If all you are doing is setting Not Pell Eligible when the value is not Pell Eligible then this update query should do it&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
update STU_GRAD_RETEN
set PELL_ELIGIBLE = "Not Pell Eligible"
where PELL_ELIGIBLE ne "Pell Eligible";
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 04:43:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Self-Update-a-Column/m-p/483667#M125455</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-08-03T04:43:39Z</dc:date>
    </item>
  </channel>
</rss>

