<?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: SET and OUTPUT same dataset within Datastep - An Issue? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SET-and-OUTPUT-same-dataset-within-Datastep-An-Issue/m-p/35849#M7090</link>
    <description>From the SAS support website - a technical paper on the topic of MODIFY (somewhat dated, but still applicable to current SAS version):&lt;BR /&gt;
&lt;BR /&gt;
TS-250&lt;BR /&gt;
DATA Step Programming Using the MODIFY Statement&lt;BR /&gt;
&lt;A href="http://support.sas.com/techsup/technote/ts250.html" target="_blank"&gt;http://support.sas.com/techsup/technote/ts250.html&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Obviously, you will want to ensure you maintain a solid backup / recovery strategy with your master database reference.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
    <pubDate>Tue, 26 May 2009 20:49:54 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2009-05-26T20:49:54Z</dc:date>
    <item>
      <title>SET and OUTPUT same dataset within Datastep - An Issue?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-and-OUTPUT-same-dataset-within-Datastep-An-Issue/m-p/35843#M7084</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
I am trying to apply some code presented by Kenneth W. Borowiak at NESUG 2006 to see if I can use HASH more efficiently to avoid a memory issue. As Kenneth mentions in his paper, the idea was presented by Paul Dorfman and Lessia Shajenko in a 2006 paper.&lt;BR /&gt;
&lt;BR /&gt;
Both these papers assume that the data for the hash is available for loading into the hash - something like the below (taken from Kenneth's&lt;BR /&gt;
paper):&lt;BR /&gt;
&lt;BR /&gt;
do until(eof_SubsetMe) ;&lt;BR /&gt;
  set SubsetMe end=eof_SubsetMe ;&lt;BR /&gt;
  n+1 ;&lt;BR /&gt;
  Sub.add() ;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
In my case, I dont have the data beforehand. I want my hash table to be loaded whenever the data is not found in the hash. My modified code is pasted below. When I run the code, it seems to get the value of 'n'&lt;BR /&gt;
correctly, but it seems to always point to the last record in maps.&amp;amp;plan._UPD_UID_HEAD_PHM_XWalk.&lt;BR /&gt;
&lt;BR /&gt;
Could there be a conflict between the datastep pointer and the direct access pointer? Once the "maps.&amp;amp;plan._UPD_UID_HEAD_PHM_XWalk" dataset is set, cannot it be updated (by the output statement)? And if yes, will it be re "SET"? I feel I am missing something fundamental about how the datastep works. Any help here is greatly appreciated.&lt;BR /&gt;
&lt;BR /&gt;
My apologies in advance if I am not including any information that might be helpful. But please let me know if you need additional information.&lt;BR /&gt;
&lt;BR /&gt;
My code:&lt;BR /&gt;
&lt;BR /&gt;
data maps.&amp;amp;plan._UPD_UID_HEAD_PHM_XWalk;&lt;BR /&gt;
    attrib clm_head length=$20 label="Clm Head"&lt;BR /&gt;
    clm_head_uid_HASH length=8 label="Clm Header UID HASH"&lt;BR /&gt;
    map_source length=$6.&lt;BR /&gt;
    ;&lt;BR /&gt;
    call missing(of _all_);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
options compress=no;&lt;BR /&gt;
data clm_head&lt;BR /&gt;
       maps.&amp;amp;plan._UPD_UID_HEAD_PHM_XWalk (keep=map_source clm_head&lt;BR /&gt;
clm_head_uid_HASH)&lt;BR /&gt;
     ;&lt;BR /&gt;
&lt;BR /&gt;
    attrib clm_head_uid length=8 label="Clm Header UID"&lt;BR /&gt;
           clm_head_uid_HASH length=8 label="Clm Header UID HASH"&lt;BR /&gt;
           Clm_Head_Match_Flag length=$1.&lt;BR /&gt;
           last_used_uid length=8&lt;BR /&gt;
           n length=5;&lt;BR /&gt;
&lt;BR /&gt;
    set clm_ds1 end=eof;&lt;BR /&gt;
&lt;BR /&gt;
    retain last_used_uid %eval(&amp;amp;last_used_uid);&lt;BR /&gt;
&lt;BR /&gt;
        if _n_ = 1 then do;&lt;BR /&gt;
            declare hash hj(hashexp:32);&lt;BR /&gt;
            hj.definekey('map_source','clm_head');&lt;BR /&gt;
            hj.definedata&lt;BR /&gt;
('map_source','clm_head','clm_head_UID_HASH');&lt;BR /&gt;
            hj.definedata('n');&lt;BR /&gt;
            hj.definedone();&lt;BR /&gt;
        end;&lt;BR /&gt;
&lt;BR /&gt;
        set &amp;amp;plan._CUR_UID_HEAD_PHM_XWalk&lt;BR /&gt;
             key=clm_head_dc / unique;&lt;BR /&gt;
&lt;BR /&gt;
        if _iorc_ = 0 then do;&lt;BR /&gt;
            Clm_Head_Match_Flag = 'Y';&lt;BR /&gt;
        end;&lt;BR /&gt;
        else do;&lt;BR /&gt;
            if clm_head=' ' then do;&lt;BR /&gt;
                Clm_Head_Match_Flag = 'Z';&lt;BR /&gt;
                clm_head_UID = .;&lt;BR /&gt;
            end;&lt;BR /&gt;
            else do;&lt;BR /&gt;
                Clm_Head_Match_Flag = 'N';&lt;BR /&gt;
&lt;BR /&gt;
                if hj.find() eq 0 then do;&lt;BR /&gt;
                    set maps.&amp;amp;plan._UPD_UID_HEAD_PHM_XWalk&lt;BR /&gt;
point=n ;&lt;BR /&gt;
                    clm_head_UID = clm_head_UID_HASH;&lt;BR /&gt;
                    clm_headx = clm_head;&lt;BR /&gt;
                    Clm_Head_Match_Flag = 'A';&lt;BR /&gt;
                end;&lt;BR /&gt;
                else do;&lt;BR /&gt;
                    clm_head_UID_HASH = last_used_uid+1;&lt;BR /&gt;
                    clm_head_UID = clm_head_uid_HASH;&lt;BR /&gt;
                    last_used_uid =&lt;BR /&gt;
clm_head_UID_HASH;&lt;BR /&gt;
                    n+1;&lt;BR /&gt;
&lt;BR /&gt;
                    rc=hj.add();&lt;BR /&gt;
&lt;BR /&gt;
                    output maps.&amp;amp;plan._UPD_UID_HEAD_PHM_XWalk;&lt;BR /&gt;
                   /* if rc=0 then Clm_Head_Match_Flag = 'A';*/&lt;BR /&gt;
                end;&lt;BR /&gt;
            end;&lt;BR /&gt;
&lt;BR /&gt;
            _iorc_=0;&lt;BR /&gt;
            _error_=0;&lt;BR /&gt;
        end;&lt;BR /&gt;
&lt;BR /&gt;
        if eof then do;&lt;BR /&gt;
            hj.delete();&lt;BR /&gt;
        end;&lt;BR /&gt;
&lt;BR /&gt;
        output clm_head;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Thank you in advance.&lt;BR /&gt;
&lt;BR /&gt;
Best,&lt;BR /&gt;
Ravi</description>
      <pubDate>Fri, 22 May 2009 19:13:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-and-OUTPUT-same-dataset-within-Datastep-An-Issue/m-p/35843#M7084</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-22T19:13:38Z</dc:date>
    </item>
    <item>
      <title>Re: SET and OUTPUT same dataset within Datastep - An Issue?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-and-OUTPUT-same-dataset-within-Datastep-An-Issue/m-p/35844#M7085</link>
      <description>The answer to your fundamental question about "dynamic update" with a SAS dataset using OUTPUT and then "referencing that same SAS dataset dynamically in the same DATA step" is no.  The SAS datasets mentioned on the DATA statement are not the same physical file that you are referencing with the SET statement, until the DATA step completes and the permanent copy (on the DATA statement) is replaced.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Mon, 25 May 2009 15:46:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-and-OUTPUT-same-dataset-within-Datastep-An-Issue/m-p/35844#M7085</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-05-25T15:46:06Z</dc:date>
    </item>
    <item>
      <title>Re: SET and OUTPUT same dataset within Datastep - An Issue?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-and-OUTPUT-same-dataset-within-Datastep-An-Issue/m-p/35845#M7086</link>
      <description>Thank you very much, Scott.&lt;BR /&gt;
I appreciate your taking the time to respond.&lt;BR /&gt;
&lt;BR /&gt;
Your answer makes total sense. I guess I was thinking wishfully!&lt;BR /&gt;
Thanks again.&lt;BR /&gt;
&lt;BR /&gt;
Ravi</description>
      <pubDate>Mon, 25 May 2009 21:48:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-and-OUTPUT-same-dataset-within-Datastep-An-Issue/m-p/35845#M7086</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-25T21:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: SET and OUTPUT same dataset within Datastep - An Issue?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-and-OUTPUT-same-dataset-within-Datastep-An-Issue/m-p/35846#M7087</link>
      <description>You will need to consider pre-processing your new input data file, creating a suitable "interim master file" for additional processing.  Options to consider are a hash table, a PROC FORMAT with a PUT function look-up, and also as you demonstrated a SET with a KEY=  approach to find a suitable match-condition.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 26 May 2009 00:35:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-and-OUTPUT-same-dataset-within-Datastep-An-Issue/m-p/35846#M7087</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-05-26T00:35:13Z</dc:date>
    </item>
    <item>
      <title>Re: SET and OUTPUT same dataset within Datastep - An Issue?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-and-OUTPUT-same-dataset-within-Datastep-An-Issue/m-p/35847#M7088</link>
      <description>when you need to change a SAS data set with "update-in-place", look at using the MODIFY statement.</description>
      <pubDate>Tue, 26 May 2009 12:08:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-and-OUTPUT-same-dataset-within-Datastep-An-Issue/m-p/35847#M7088</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2009-05-26T12:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: SET and OUTPUT same dataset within Datastep - An Issue?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-and-OUTPUT-same-dataset-within-Datastep-An-Issue/m-p/35848#M7089</link>
      <description>Hi Scott, Peter:&lt;BR /&gt;
&lt;BR /&gt;
Thank you for your thoughts.&lt;BR /&gt;
&lt;BR /&gt;
I have updated my process to do something like what Scott suggested above. Basically, I moved the "if hj.find() = 0" do block to a different data step which follows the above one. Now my process works the way I intended it to.&lt;BR /&gt;
&lt;BR /&gt;
But I will look into the Modify statement to see if I can use it, because then I can avoid reading the two datasets again. I need to study if direct accessing works with Modify and probably other things that may cause issues.&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Ravi</description>
      <pubDate>Tue, 26 May 2009 19:40:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-and-OUTPUT-same-dataset-within-Datastep-An-Issue/m-p/35848#M7089</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-26T19:40:28Z</dc:date>
    </item>
    <item>
      <title>Re: SET and OUTPUT same dataset within Datastep - An Issue?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-and-OUTPUT-same-dataset-within-Datastep-An-Issue/m-p/35849#M7090</link>
      <description>From the SAS support website - a technical paper on the topic of MODIFY (somewhat dated, but still applicable to current SAS version):&lt;BR /&gt;
&lt;BR /&gt;
TS-250&lt;BR /&gt;
DATA Step Programming Using the MODIFY Statement&lt;BR /&gt;
&lt;A href="http://support.sas.com/techsup/technote/ts250.html" target="_blank"&gt;http://support.sas.com/techsup/technote/ts250.html&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Obviously, you will want to ensure you maintain a solid backup / recovery strategy with your master database reference.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 26 May 2009 20:49:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-and-OUTPUT-same-dataset-within-Datastep-An-Issue/m-p/35849#M7090</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-05-26T20:49:54Z</dc:date>
    </item>
  </channel>
</rss>

