<?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: Implied retain in SET statement? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Implied-retain-in-SET-statement/m-p/71249#M15415</link>
    <description>An easy way to get this working is to do your own INIT to MISSING using CALL MISSING.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data strange;&lt;BR /&gt;
   set data1 data2;&lt;BR /&gt;
   if dob=. then dob=input(strip(person_dob),yymmdd8.);&lt;BR /&gt;
   if age=. then age=input(person_age,8.);&lt;BR /&gt;
   *drop person_age person_dob;&lt;BR /&gt;
&lt;B&gt;   output;&lt;BR /&gt;
   call missing(of _all_);&lt;/B&gt;   &lt;BR /&gt;
   format dob yymmddn8.;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
    <pubDate>Fri, 10 Sep 2010 16:42:33 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2010-09-10T16:42:33Z</dc:date>
    <item>
      <title>Implied retain in SET statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Implied-retain-in-SET-statement/m-p/71247#M15413</link>
      <description>I have some datasets that contain the same information for three separate years, however, the variable names from year to year are inconsistent. I needed these all in one dataset with uniform variable names.  &lt;BR /&gt;
&lt;BR /&gt;
Originally, I was hoping to just use the rename= option, however there are several variables which are defined as numeric in one dataset and character in another.  So my solution was to just put all the datasets in a SET statement to combine them and then sort out the variable names later in the same data step. &lt;BR /&gt;
&lt;BR /&gt;
Here is an example which illustrates what I am trying to do, as well as the confusing output I am receiving:&lt;BR /&gt;
&lt;BR /&gt;
--------------------------------------------------------------&lt;BR /&gt;
data data1;&lt;BR /&gt;
infile datalines;&lt;BR /&gt;
input @1 name  $15.  @17 dob yymmdd8.  @26 age;&lt;BR /&gt;
datalines;&lt;BR /&gt;
John Smith      19851225  25&lt;BR /&gt;
Jack Bauer      19600704  50&lt;BR /&gt;
Charlie Day      19791021  31&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data data2;&lt;BR /&gt;
infile datalines;&lt;BR /&gt;
input @1 name  $15.  @17 person_dob  @26 person_age $2.;&lt;BR /&gt;
datalines;&lt;BR /&gt;
Patrick Stewart 19500406  60&lt;BR /&gt;
Steve Jobs        19520115  58&lt;BR /&gt;
Bill Gates          19510803  59&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data strange;&lt;BR /&gt;
set data1 data2;&lt;BR /&gt;
&lt;BR /&gt;
if dob=. then dob=input(strip(person_dob),yymmdd8.);&lt;BR /&gt;
if age=. then age=input(person_age,8.);&lt;BR /&gt;
*drop person_age person_dob;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
OUTPUT:&lt;BR /&gt;
proc print data=strange;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
                                                  &lt;BR /&gt;
                      Obs    name                dob     age       person_dob       person_ age&lt;BR /&gt;
&lt;BR /&gt;
                       1     John Smith          9490    25           .&lt;BR /&gt;
                       2     Jack Bauer          185      50           .&lt;BR /&gt;
                       3     Charlie Day          7233    31           .&lt;BR /&gt;
                       4     Patrick Stewart    -3557    60      19500406            60&lt;BR /&gt;
                       5     Steve Jobs          -3557    60      19520115             58&lt;BR /&gt;
                       6     Bill Gates            -3557    60      19510803            59&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-------------------------------------------------------------------------------&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
As you can see from the output, the values for "dob" and "age" do not populate as (I) expected.  The if conditions are only being tested on the first observation. The new values are set and then retained so the if condition fails on all further observations because the variables all have values.&lt;BR /&gt;
&lt;BR /&gt;
I am confused as to why the values are being retained.  I was under the impression that since the next observation being read in had missing values for these variables, they would not be retained.  Am I thinking about this incorrectly?  My guess is that it has to to with the variable already being present in the dataset, however, I would like to know what is actually happening?&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Brian</description>
      <pubDate>Fri, 10 Sep 2010 15:45:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Implied-retain-in-SET-statement/m-p/71247#M15413</guid>
      <dc:creator>BrianDiamante</dc:creator>
      <dc:date>2010-09-10T15:45:25Z</dc:date>
    </item>
    <item>
      <title>Re: Implied retain in SET statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Implied-retain-in-SET-statement/m-p/71248#M15414</link>
      <description>No input observation on WORK.DATA2 contributed a value for DOB so the PDV is not updated, and so you will have the most recent assigned value.  My suggestion would be to test the "source" CHARACTER variable and consider renaming any incoming NUMERIC/CHARACTER variable so that it is unique.  Or set DOB back to MISSING after doing an explicit OUTPUT in your last DATA step.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 10 Sep 2010 16:39:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Implied-retain-in-SET-statement/m-p/71248#M15414</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-09-10T16:39:20Z</dc:date>
    </item>
    <item>
      <title>Re: Implied retain in SET statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Implied-retain-in-SET-statement/m-p/71249#M15415</link>
      <description>An easy way to get this working is to do your own INIT to MISSING using CALL MISSING.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data strange;&lt;BR /&gt;
   set data1 data2;&lt;BR /&gt;
   if dob=. then dob=input(strip(person_dob),yymmdd8.);&lt;BR /&gt;
   if age=. then age=input(person_age,8.);&lt;BR /&gt;
   *drop person_age person_dob;&lt;BR /&gt;
&lt;B&gt;   output;&lt;BR /&gt;
   call missing(of _all_);&lt;/B&gt;   &lt;BR /&gt;
   format dob yymmddn8.;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Fri, 10 Sep 2010 16:42:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Implied-retain-in-SET-statement/m-p/71249#M15415</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-09-10T16:42:33Z</dc:date>
    </item>
    <item>
      <title>Re: Implied retain in SET statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Implied-retain-in-SET-statement/m-p/71250#M15416</link>
      <description>Thanks guys.&lt;BR /&gt;
&lt;BR /&gt;
I see... so because there is no DOB in work.data2, and I had already assigned a value to DOB for the first observation is keeps that value throughout.  To clarify, if I was to create both dob and age in work.data2, and initialize them to missing, these values would then update the PDV and overwrite the current values of DOB and AGE as each observation is read in?&lt;BR /&gt;
&lt;BR /&gt;
I went ahead and updated my program as per your suggestions.&lt;BR /&gt;
&lt;BR /&gt;
Thanks again!&lt;BR /&gt;
Brian</description>
      <pubDate>Fri, 10 Sep 2010 18:05:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Implied-retain-in-SET-statement/m-p/71250#M15416</guid>
      <dc:creator>BrianDiamante</dc:creator>
      <dc:date>2010-09-10T18:05:35Z</dc:date>
    </item>
    <item>
      <title>Re: Implied retain in SET statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Implied-retain-in-SET-statement/m-p/71251#M15417</link>
      <description>Hi:&lt;BR /&gt;
  A good technique for diagnosing issues like the one you experienced is to use the PUT or PUTLOG statement to write selected variables from the Progarm Data Vector (PDV) as a debugging technique. For  example, the log below shows the result of using PUTLOG statements to see what was happening in your program with the DOB and AGE variables:&lt;BR /&gt;
[pre]&lt;BR /&gt;
1671  ** diagnose initialization issues with 2 set statements;&lt;BR /&gt;
1672  ** and see how using IN= might help;&lt;BR /&gt;
1673  data diagnose;&lt;BR /&gt;
1674  set data1(in=inone) data2(in=intwo);&lt;BR /&gt;
1675  putlog '***';&lt;BR /&gt;
1676  putlog '***** After SET';&lt;BR /&gt;
1677  put _n_ inone= intwo= name= dob= age= person_dob= person_age= xdob= xage=;&lt;BR /&gt;
1678&lt;BR /&gt;
1679  if dob=. then dob=input(put(person_dob,8.),yymmdd8.);&lt;BR /&gt;
1680  if age=. then age=input(person_age,8.);&lt;BR /&gt;
1681&lt;BR /&gt;
1682  *** make OTHER variables not in either dataset;&lt;BR /&gt;
1683  *** XDOB and XAGE will ONLY be created when an obs comes;&lt;BR /&gt;
1684  *** from DATA2 dataset.;&lt;BR /&gt;
1685  if intwo then do;&lt;BR /&gt;
1686    xdob=input(put(person_dob,8.),yymmdd8.);&lt;BR /&gt;
1687    xage=input(person_age,8.);&lt;BR /&gt;
1688  end;&lt;BR /&gt;
1689&lt;BR /&gt;
1690  putlog '***** After IF for DOB and AGE';&lt;BR /&gt;
1691  put _n_ inone= intwo= name= dob= age= person_dob= person_age= xdob= xage=;&lt;BR /&gt;
1692  run;&lt;BR /&gt;
                                         &lt;BR /&gt;
***&lt;BR /&gt;
***** After SET&lt;BR /&gt;
1 inone=1 intwo=0 name=John Smith dob=9490 age=25 person_dob=. person_age=  xdob=. xage=.&lt;BR /&gt;
***** After IF for DOB and AGE&lt;BR /&gt;
1 inone=1 intwo=0 name=John Smith dob=9490 age=25 person_dob=. person_age=  xdob=. xage=.&lt;BR /&gt;
***&lt;BR /&gt;
***** After SET&lt;BR /&gt;
2 inone=1 intwo=0 name=Jack Bauer dob=185 age=50 person_dob=. person_age=  xdob=. xage=.&lt;BR /&gt;
***** After IF for DOB and AGE&lt;BR /&gt;
2 inone=1 intwo=0 name=Jack Bauer dob=185 age=50 person_dob=. person_age=  xdob=. xage=.&lt;BR /&gt;
***&lt;BR /&gt;
***** After SET&lt;BR /&gt;
3 inone=1 intwo=0 name=Charlie Day dob=7233 age=31 person_dob=. person_age=  xdob=. xage=.&lt;BR /&gt;
***** After IF for DOB and AGE&lt;BR /&gt;
3 inone=1 intwo=0 name=Charlie Day dob=7233 age=31 person_dob=. person_age=  xdob=. xage=.&lt;BR /&gt;
***&lt;BR /&gt;
***** After SET&lt;BR /&gt;
4 inone=0 intwo=1 name=Patrick Stewart dob=. age=. person_dob=19500406 person_age=60 xdob=. xage=.&lt;BR /&gt;
***** After IF for DOB and AGE&lt;BR /&gt;
4 inone=0 intwo=1 name=Patrick Stewart dob=-3557 age=60 person_dob=19500406 person_age=60 xdob=-3557 xage=60&lt;BR /&gt;
***&lt;BR /&gt;
***** After SET&lt;BR /&gt;
5 inone=0 intwo=1 name=Steve Jobs dob=-3557 age=60 person_dob=19520115 person_age=58 xdob=. xage=.&lt;BR /&gt;
***** After IF for DOB and AGE&lt;BR /&gt;
5 inone=0 intwo=1 name=Steve Jobs dob=-3557 age=60 person_dob=19520115 person_age=58 xdob=-2908 xage=58&lt;BR /&gt;
***&lt;BR /&gt;
***** After SET&lt;BR /&gt;
6 inone=0 intwo=1 name=Bill Gates dob=-3557 age=60 person_dob=19510803 person_age=59 xdob=. xage=.&lt;BR /&gt;
***** After IF for DOB and AGE&lt;BR /&gt;
6 inone=0 intwo=1 name=Bill Gates dob=-3557 age=60 person_dob=19510803 person_age=59 xdob=-3073 xage=59&lt;BR /&gt;
NOTE: There were 3 observations read from the data set WORK.DATA1.&lt;BR /&gt;
NOTE: There were 3 observations read from the data set WORK.DATA2.&lt;BR /&gt;
NOTE: The data set WORK.DIAGNOSE has 6 observations and 7 variables.&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.01 seconds&lt;BR /&gt;
      cpu time            0.01 seconds&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                        &lt;BR /&gt;
In addition to creating XDOB and XAGE so you could see the difference in initialization for those two variables versus the way you did it (by reusing existing variables that came from DATA1, I also show the use of the IN= data set option so you might check it out as a different way to do your test. Finally, I have a simpler suggestion for how to do the creation of the variables where you need to do the conversion for DATA2 obs (shown in the program below). Also, I showed the use of the INPUT function with the PUT function to get rid of "automatic conversion" messages in the SAS log.&lt;BR /&gt;
 &lt;BR /&gt;
Alternate suggestion:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data simpler;&lt;BR /&gt;
set data1(in=inone) data2(in=intwo);&lt;BR /&gt;
** only create dob and age for observations from DATA2;&lt;BR /&gt;
** you avoid the issue of testing for missing dob and age because;&lt;BR /&gt;
** you know that variables from DATA2 will ONLY fall into the IF condition.;&lt;BR /&gt;
if intwo then do;&lt;BR /&gt;
  dob=input(put(person_dob,8.),yymmdd8.);&lt;BR /&gt;
  age=input(person_age,8.);&lt;BR /&gt;
end;&lt;BR /&gt;
*drop person_age person_dob;&lt;BR /&gt;
run;&lt;BR /&gt;
                      &lt;BR /&gt;
proc print data=simpler;&lt;BR /&gt;
format dob yymmdd10.;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                    &lt;BR /&gt;
cynthia</description>
      <pubDate>Fri, 10 Sep 2010 20:48:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Implied-retain-in-SET-statement/m-p/71251#M15417</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-09-10T20:48:52Z</dc:date>
    </item>
    <item>
      <title>Re: Implied retain in SET statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Implied-retain-in-SET-statement/m-p/71252#M15418</link>
      <description>The basic problem is that two different operations (pre-processing of data2 variables and appending data2 to data1) are crammed together in a data step. IMHO, both the manual pdv refreshing and the conditional processing relying on the in= ds option variable seem contrived. (besides, the in= ds option for data1 is not used at all)&lt;BR /&gt;
&lt;BR /&gt;
The pre-processing of the data2 should and can be separated without any performance penalty using a view. Things like this are what views are for.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data data1;&lt;BR /&gt;
  infile datalines firstobs=2;&lt;BR /&gt;
  input @1 name $15. @17 dob yymmdd8. @26 age;&lt;BR /&gt;
datalines;&lt;BR /&gt;
----+----1----+----2----+-&lt;BR /&gt;
John Smith      19851225 25&lt;BR /&gt;
Jack Bauer      19600704 50&lt;BR /&gt;
Charlie Day     19791021 31&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data data2;&lt;BR /&gt;
  infile datalines firstobs=2;&lt;BR /&gt;
  input @1 name $15. @17 person_dob @26 person_age $2.;&lt;BR /&gt;
datalines;&lt;BR /&gt;
----+----1----+----2----+-&lt;BR /&gt;
Patrick Stewart 19500406 60&lt;BR /&gt;
Steve Jobs      19520115 58&lt;BR /&gt;
Bill Gates      19510803 59&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data view2/view=view2;&lt;BR /&gt;
  set data2;&lt;BR /&gt;
  dob = input(strip(person_dob), yymmdd8.);&lt;BR /&gt;
  format dob yymmdd8.;&lt;BR /&gt;
  age = input(person_age, best.);&lt;BR /&gt;
  keep name dob age;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data both;&lt;BR /&gt;
  set data1 view2;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* check */&lt;BR /&gt;
proc print data=both;&lt;BR /&gt;
run;&lt;BR /&gt;
/*&lt;BR /&gt;
Obs    name                    dob    age&lt;BR /&gt;
 1     John Smith         85-12-25     25&lt;BR /&gt;
 2     Jack Bauer         60-07-04     50&lt;BR /&gt;
 3     Charlie Day        79-10-21     31&lt;BR /&gt;
 4     Patrick Stewart    50-04-06     60&lt;BR /&gt;
 5     Steve Jobs         52-01-15     58&lt;BR /&gt;
 6     Bill Gates         51-08-03     59&lt;BR /&gt;
*/&lt;BR /&gt;
[/pre]</description>
      <pubDate>Fri, 10 Sep 2010 22:23:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Implied-retain-in-SET-statement/m-p/71252#M15418</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2010-09-10T22:23:02Z</dc:date>
    </item>
  </channel>
</rss>

