<?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 Hash object in proc DS2 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Hash-object-in-proc-DS2/m-p/894376#M353292</link>
    <description>&lt;P&gt;Hello!&lt;BR /&gt;How to use hash object inside proc DS2, this code porduces Error:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc ds2;
    data cars_test_two / overwrite=yes;
        /* Variable declarations */
        declare char(13) Make;
        declare char(8) Type; /* Adjusted length based on 'Sedan' */
        declare int _rc;

        /* Declare the hash object */
        declare package.hash codes();
        _rc = codes.defineKey('Make', 'Type');
        _rc = codes.defineDone();

        /* Load codes into hash object */
        method init(); 
            Make = 'Akura'; 
            Type = 'Sedan';
            _rc = codes.add();
            
            Make = 'Audi'; 
            Type = 'Sedan';
            _rc = codes.add();
        end;

        method run();
            set sashelp.cars (drop = DriveTrain);

            if codes.check() = 0 then
                output;
        end;
    enddata;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;DIV class=""&gt;ERROR: Compilation error.&lt;/DIV&gt;&lt;DIV class=""&gt;ERROR: Parse encountered RC when expecting identifier.&lt;/DIV&gt;&lt;DIV class=""&gt;ERROR: Line 74: Parse failed: declare int &amp;gt;&amp;gt;&amp;gt; _rc &amp;lt;&amp;lt;&amp;lt; ;&lt;BR /&gt;Please help to correct code.&lt;/DIV&gt;</description>
    <pubDate>Thu, 14 Sep 2023 20:16:53 GMT</pubDate>
    <dc:creator>JanKwiatkowski</dc:creator>
    <dc:date>2023-09-14T20:16:53Z</dc:date>
    <item>
      <title>Hash object in proc DS2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-object-in-proc-DS2/m-p/894376#M353292</link>
      <description>&lt;P&gt;Hello!&lt;BR /&gt;How to use hash object inside proc DS2, this code porduces Error:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc ds2;
    data cars_test_two / overwrite=yes;
        /* Variable declarations */
        declare char(13) Make;
        declare char(8) Type; /* Adjusted length based on 'Sedan' */
        declare int _rc;

        /* Declare the hash object */
        declare package.hash codes();
        _rc = codes.defineKey('Make', 'Type');
        _rc = codes.defineDone();

        /* Load codes into hash object */
        method init(); 
            Make = 'Akura'; 
            Type = 'Sedan';
            _rc = codes.add();
            
            Make = 'Audi'; 
            Type = 'Sedan';
            _rc = codes.add();
        end;

        method run();
            set sashelp.cars (drop = DriveTrain);

            if codes.check() = 0 then
                output;
        end;
    enddata;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;DIV class=""&gt;ERROR: Compilation error.&lt;/DIV&gt;&lt;DIV class=""&gt;ERROR: Parse encountered RC when expecting identifier.&lt;/DIV&gt;&lt;DIV class=""&gt;ERROR: Line 74: Parse failed: declare int &amp;gt;&amp;gt;&amp;gt; _rc &amp;lt;&amp;lt;&amp;lt; ;&lt;BR /&gt;Please help to correct code.&lt;/DIV&gt;</description>
      <pubDate>Thu, 14 Sep 2023 20:16:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-object-in-proc-DS2/m-p/894376#M353292</guid>
      <dc:creator>JanKwiatkowski</dc:creator>
      <dc:date>2023-09-14T20:16:53Z</dc:date>
    </item>
    <item>
      <title>Re: Hash object in proc DS2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-object-in-proc-DS2/m-p/894480#M353328</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/448802"&gt;@JanKwiatkowski&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am a beginner when it comes to PROC DS2, but after fixing &lt;EM&gt;seven&lt;/EM&gt; errors indicated in the logs (one per run) the code worked.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;PROC DS2 doesn't seem to like the variable name &lt;FONT face="courier new,courier"&gt;_rc&lt;/FONT&gt;. Changed it to &lt;FONT face="courier new,courier"&gt;rc&lt;/FONT&gt; (but &lt;FONT face="courier new,courier"&gt;_test&lt;/FONT&gt; works as well, so the underscore is not the issue).&lt;/LI&gt;
&lt;LI&gt;Replaced the period between "&lt;FONT face="courier new,courier"&gt;package&lt;/FONT&gt;" and "&lt;FONT face="courier new,courier"&gt;hash&lt;/FONT&gt;" with a blank.&lt;/LI&gt;
&lt;LI&gt;The DEFINEKEY and DEFINEDONE methods (unlike their siblings in the traditional DATA step) don't seem to create return codes.&lt;/LI&gt;
&lt;LI&gt;The &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/ds2ref/p13mhz1l14omjon1b5ezpqux0drd.htm" target="_blank" rel="noopener"&gt;DEFINEKEY method&lt;/A&gt; accepts only one argument at a time, so I called it twice. This limitation does not exist in the DATA step. &lt;EM&gt;&lt;U&gt;Edit:&lt;/U&gt;&lt;/EM&gt;&amp;nbsp; But there is a &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/ds2ref/p1fvhhqgmw97v4n1ck33bnigp8t0.htm" target="_blank" rel="noopener"&gt;KEYS method&lt;/A&gt;, which &lt;EM&gt;does&lt;/EM&gt; accept variable lists, of course using a different syntax than the DEFINEKEY method: &lt;FONT face="courier new,courier"&gt;codes.keys([Make Type]);&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;Had to move "&lt;FONT face="courier new,courier"&gt;method init();&lt;/FONT&gt;" before the&amp;nbsp;DEFINEKEY and DEFINEDONE method calls. So, this part of the program now looks like this:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Declare the hash object */
declare package hash codes();
method init(); 
codes.defineKey('Make');
codes.defineKey('Type');
codes.defineDone();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;LI&gt;Another DS2 vs. DATA step difference: The DROP= dataset option requires parentheses around the list of variable names (see below).&lt;/LI&gt;
&lt;LI&gt;PROC DS2 doesn't like concatenated libraries such as SASHELP. (Found this information in the 2016 thread &lt;A href="https://communities.sas.com/t5/SAS-Programming/Basic-PROC-DS2-Questions/m-p/301589/highlight/true#M63855" target="_blank" rel="noopener"&gt;Basic PROC DS2 Questions&lt;/A&gt;.) Simple libraries like my WORK library (or simple permanent libraries) can be used. So I created a work copy of SASHELP.CARS and used this:&amp;nbsp;&lt;BR /&gt;
&lt;PRE&gt;set cars (drop = &lt;FONT size="3" color="#3366FF"&gt;&lt;STRONG&gt;(&lt;/STRONG&gt;&lt;/FONT&gt;DriveTrain&lt;FONT size="3"&gt;&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;);​&lt;/PRE&gt;
&lt;/LI&gt;
&lt;LI&gt;Optional (just to avoid an unnecessary note in the log)&lt;FONT face="helvetica"&gt;:&lt;/FONT&gt;&amp;nbsp;Either declare variable &lt;FONT face="courier new,courier"&gt;rc&lt;/FONT&gt; as &lt;FONT face="courier new,courier"&gt;double&lt;/FONT&gt; (because &lt;FONT face="courier new,courier"&gt;int&lt;/FONT&gt;&amp;nbsp;"is not supported by the BASE driver") or, better, drop it from the output dataset:&lt;BR /&gt;
&lt;PRE&gt;data cars_test_two (drop = (rc)) / overwrite=yes;​&lt;/PRE&gt;
&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Fri, 15 Sep 2023 13:46:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-object-in-proc-DS2/m-p/894480#M353328</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-09-15T13:46:08Z</dc:date>
    </item>
  </channel>
</rss>

