<?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 Basic PROC DS2 Questions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Basic-PROC-DS2-Questions/m-p/251467#M47524</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Apologies for the basic questions. &amp;nbsp;I've read the first 1/2 of the PROC DS2 Language Reference but still have the below issues.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc ds2;
   data class(overwrite=yes);
      method run();
         set sashelp.class;
      end;
   enddata;
   run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR: Compilation error.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR: BASE driver, schema name SASHELP was not found for this connection&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR: Table "SASHELP.CLASS" does not exist or cannot be accessed&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR: Line 26: Unable to prepare SELECT statement for table class (rc=0x80fff802U).&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I make PROC DS2 recognize the pre-allocated SASHELP library (and WORK/other libraries)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
   set sashelp.class;
run;

proc ds2;
   data class(overwrite=yes);
      method run();
         set class;
      end;
   enddata;
   run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR: Compilation error.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: Base table or view already exists CLASS&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: Unable to execute CREATE TABLE statement for table work.class.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;How do I update a table in place using DS2 (if possible)?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;FONT color="#000000"&gt;&lt;CODE class=" language-sas"&gt;proc ds2;
   data class2(overwrite=yes);
      method init();
         if 0 then set class (locktable=share);
      end;
      method run();
         set class (keep=(name));
         if _n_ le 7 then age=_n_;
      end;
   enddata;
   run;
quit;&lt;/CODE&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;The "if 0 then set..." paradigm is often used with hash object processing to dynamically set the attributes of the hash object variables. &amp;nbsp;However, a caveat is the implied retain for data set variables. &amp;nbsp;This program illustrates the issue; I'd want age=. for _n_ &amp;gt; 7.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;FONT color="#000000"&gt;&lt;CODE class=" language-sas"&gt;proc ds2;
   data class2(overwrite=yes);
      method init();
         if 0 then set class (locktable=share);
      end;
      method run();
         call missing(of _all_);  * &amp;lt;&amp;lt;&amp;lt; ;
         set class (keep=(name));
         if _n_ le 7 then age=_n_;
      end;
   enddata;
   run;
quit;&lt;/CODE&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;This is how I usually deal with this issue in my "old style" data step code. &amp;nbsp;But this yields:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR: Compilation error.&lt;BR /&gt;ERROR: Missing END statement for the method run.&lt;BR /&gt;ERROR: Parse encountered CALL when expecting end of input.&lt;BR /&gt;ERROR: Line 29: Parse failed: &amp;gt;&amp;gt;&amp;gt; call &amp;lt;&amp;lt;&amp;lt; missing(of _all_);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Is there a way to explicitly set a list of variables to missing in DS2?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc ds2;
   data test(overwrite=yes);
      method init();
         declare package hash h(
            [name],
            [age sex],
            16,
            {select name, age, sex from work.class where sex='F'}
         );
      end;
      method run();
      end;
   enddata;
   run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;FONT color="#339966"&gt;WARNING: Line 27: No DECLARE for referenced variable name; creating it as a global variable of type double.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;WARNING: Line 28: No DECLARE for referenced variable age; creating it as a global variable of type double.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;WARNING: Line 28: No DECLARE for referenced variable sex; creating it as a global variable of type double.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: Syntax error at or near "WORK.0"&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: Unable to prepare statement for hash data source 0.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: Error reported by DS2 package d2hash:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: Hash data source load failed.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: Fatal run-time error.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: General error&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;FONT color="#000000"&gt;&lt;CODE class=" language-sas"&gt;proc ds2;
   data test(overwrite=yes);
      method init();
         if 0 then set class (keep=(name age sex));
         declare package hash h(
            [name],
            [age sex],
            16,
            {select name, age, sex from work.class where sex='F'}
         );
      end;
      method run();
         set class (keep=(name));
         rc=h.find();
         drop rc;
      end;
   enddata;
   run;
quit;&lt;/CODE&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR: Compilation error.&lt;BR /&gt;ERROR: Missing END statement for the method init.&lt;BR /&gt;ERROR: Parse encountered DECLARE when expecting end of input.&lt;BR /&gt;ERROR: Line 27: Parse failed: &amp;gt;&amp;gt;&amp;gt; declare &amp;lt;&amp;lt;&amp;lt; package hash h(&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Any hints on how to code this?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Thanks,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Scott&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 22 Feb 2016 04:15:38 GMT</pubDate>
    <dc:creator>ScottBass</dc:creator>
    <dc:date>2016-02-22T04:15:38Z</dc:date>
    <item>
      <title>Basic PROC DS2 Questions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Basic-PROC-DS2-Questions/m-p/251467#M47524</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Apologies for the basic questions. &amp;nbsp;I've read the first 1/2 of the PROC DS2 Language Reference but still have the below issues.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc ds2;
   data class(overwrite=yes);
      method run();
         set sashelp.class;
      end;
   enddata;
   run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR: Compilation error.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR: BASE driver, schema name SASHELP was not found for this connection&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR: Table "SASHELP.CLASS" does not exist or cannot be accessed&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR: Line 26: Unable to prepare SELECT statement for table class (rc=0x80fff802U).&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I make PROC DS2 recognize the pre-allocated SASHELP library (and WORK/other libraries)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
   set sashelp.class;
run;

proc ds2;
   data class(overwrite=yes);
      method run();
         set class;
      end;
   enddata;
   run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR: Compilation error.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: Base table or view already exists CLASS&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: Unable to execute CREATE TABLE statement for table work.class.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;How do I update a table in place using DS2 (if possible)?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;FONT color="#000000"&gt;&lt;CODE class=" language-sas"&gt;proc ds2;
   data class2(overwrite=yes);
      method init();
         if 0 then set class (locktable=share);
      end;
      method run();
         set class (keep=(name));
         if _n_ le 7 then age=_n_;
      end;
   enddata;
   run;
quit;&lt;/CODE&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;The "if 0 then set..." paradigm is often used with hash object processing to dynamically set the attributes of the hash object variables. &amp;nbsp;However, a caveat is the implied retain for data set variables. &amp;nbsp;This program illustrates the issue; I'd want age=. for _n_ &amp;gt; 7.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;FONT color="#000000"&gt;&lt;CODE class=" language-sas"&gt;proc ds2;
   data class2(overwrite=yes);
      method init();
         if 0 then set class (locktable=share);
      end;
      method run();
         call missing(of _all_);  * &amp;lt;&amp;lt;&amp;lt; ;
         set class (keep=(name));
         if _n_ le 7 then age=_n_;
      end;
   enddata;
   run;
quit;&lt;/CODE&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;This is how I usually deal with this issue in my "old style" data step code. &amp;nbsp;But this yields:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR: Compilation error.&lt;BR /&gt;ERROR: Missing END statement for the method run.&lt;BR /&gt;ERROR: Parse encountered CALL when expecting end of input.&lt;BR /&gt;ERROR: Line 29: Parse failed: &amp;gt;&amp;gt;&amp;gt; call &amp;lt;&amp;lt;&amp;lt; missing(of _all_);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Is there a way to explicitly set a list of variables to missing in DS2?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc ds2;
   data test(overwrite=yes);
      method init();
         declare package hash h(
            [name],
            [age sex],
            16,
            {select name, age, sex from work.class where sex='F'}
         );
      end;
      method run();
      end;
   enddata;
   run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;FONT color="#339966"&gt;WARNING: Line 27: No DECLARE for referenced variable name; creating it as a global variable of type double.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;WARNING: Line 28: No DECLARE for referenced variable age; creating it as a global variable of type double.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;WARNING: Line 28: No DECLARE for referenced variable sex; creating it as a global variable of type double.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: Syntax error at or near "WORK.0"&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: Unable to prepare statement for hash data source 0.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: Error reported by DS2 package d2hash:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: Hash data source load failed.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: Fatal run-time error.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: General error&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;FONT color="#000000"&gt;&lt;CODE class=" language-sas"&gt;proc ds2;
   data test(overwrite=yes);
      method init();
         if 0 then set class (keep=(name age sex));
         declare package hash h(
            [name],
            [age sex],
            16,
            {select name, age, sex from work.class where sex='F'}
         );
      end;
      method run();
         set class (keep=(name));
         rc=h.find();
         drop rc;
      end;
   enddata;
   run;
quit;&lt;/CODE&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR: Compilation error.&lt;BR /&gt;ERROR: Missing END statement for the method init.&lt;BR /&gt;ERROR: Parse encountered DECLARE when expecting end of input.&lt;BR /&gt;ERROR: Line 27: Parse failed: &amp;gt;&amp;gt;&amp;gt; declare &amp;lt;&amp;lt;&amp;lt; package hash h(&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Any hints on how to code this?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Thanks,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Scott&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2016 04:15:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Basic-PROC-DS2-Questions/m-p/251467#M47524</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2016-02-22T04:15:38Z</dc:date>
    </item>
    <item>
      <title>Re: Basic PROC DS2 Questions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Basic-PROC-DS2-Questions/m-p/251470#M47526</link>
      <description>&lt;P&gt;A couple more examples...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This works:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   if 0 then set class;
   call missing(of _all_);
   if _n_=1 then do;
      declare hash h(dataset: 'class (where=(sex="F"))');
      h.defineKey('name');
      h.defineData('age');
      h.defineData('sex');
      h.defineDone();
   end;
   stop;
run;

proc ds2;
   data test(overwrite=yes);
      declare char(10) name;
      declare double age;
      declare char(1) sex;
      method init();
         declare package hash h();
         h.defineKey('name');
         h.defineData('age');
         h.defineData('sex');
         h.dataset('class');
         h.defineDone();
      end;
      method run();
         stop;
      end;
   enddata;
   run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But this fails:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc ds2;
   data test(overwrite=yes);
      declare char(10) name;
      declare double age;
      declare char(1) sex;
      method init();
         declare package hash h();
         h.defineKey('name');
         h.defineData('age');
         h.defineData('sex');
         h.dataset('class (where=(age=12))');
         h.defineDone();
      end;
   enddata;
   run;
quit;

proc ds2;
   data test(overwrite=yes);
      declare char(10) name;
      declare double age;
      declare char(1) sex;
      method init();
         declare package hash h();
         h.defineKey('name');
         h.defineData('age');
         h.defineData('sex');
         h.dataset({select * from class where sex='F'});
         h.defineDone();
      end;
   enddata;
   run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Yet this works:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc ds2;
   data test(overwrite=yes);
      method run();
         set {select * from class where sex='F'};
      end;
   enddata;
   run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'd like to load the hash object (package) using a where clause, like I can in the traditional data step. &amp;nbsp;Do I need to use a view instead? &amp;nbsp;The doc implies that I should be able to use an SQL query as a data source for the hash.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Minor: &amp;nbsp;when I use PROC DS2 in EG, the created datasets don't show up in the project. &amp;nbsp;Why is that? &amp;nbsp;I'm using a recent version of EG (7.11 HF2 (7.100.1.2785) (32-bit)).&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2016 05:07:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Basic-PROC-DS2-Questions/m-p/251470#M47526</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2016-02-22T05:07:46Z</dc:date>
    </item>
    <item>
      <title>Re: Basic PROC DS2 Questions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Basic-PROC-DS2-Questions/m-p/301589#M63855</link>
      <description>&lt;P&gt;I had the same problem and this post was the only one that came up when I searched for the error message.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bit more digging and it appears the issue is because SASHELP is a concatenated libname and these are not supported in DS2. &amp;nbsp;See SAS usage note 51043 (&amp;nbsp;&lt;A href="http://support.sas.com/kb/51/043.html" target="_blank"&gt;http://support.sas.com/kb/51/043.html&lt;/A&gt; )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Posted here in case some else comes a lookin'&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2016 18:19:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Basic-PROC-DS2-Questions/m-p/301589#M63855</guid>
      <dc:creator>JonathanWill</dc:creator>
      <dc:date>2016-09-29T18:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: Basic PROC DS2 Questions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Basic-PROC-DS2-Questions/m-p/399255#M96690</link>
      <description>&lt;P&gt;Hi Scott-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a bugfix for one of the examples:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc ds2;
   data test(overwrite=yes);
      declare char(10) name;
      declare double age;
      declare char(1) sex;
      method init();
         declare package hash h();
         h.defineKey('name');
         h.defineData('age');
         h.defineData('sex');   
         h.dataset(%tslit({select * from class where sex='F'}));
        /* h.dataset({select * from class where sex='F'}); */
         h.defineDone();
      end;
   enddata;
   run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;The fix was to add single quotes outside the brackets inside the h.dataset() query. Actually, since your query contains single quotes in one of the clauses, you can't add quotes because this messes up the syntax parser. So you have to use the %TSLIT() function as per &lt;A title="Solutions for missing DATA step features within DS2" href="https://blogs.sas.com/content/sgf/2016/04/22/solutions-for-many-of-the-missing-data-step-features-within-ds2/" target="_self"&gt;Solutions for missing DATA step features within DS2&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now a solution to&amp;nbsp;get the variable attributes into the hash without needing to explicitly&amp;nbsp;define their type:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create an empty class that just has the variable we need */
data skeleton_class;
	if _n_=0 then
		set class(keep=name age sex);
run;

/*
	Create a copy of the original data set. Apparently there is a
	lock error if the same class is used in the h.dataset() statement
	and the SET statement in the run() method. I tried creating this
	with the /view option, but there was still a lock error.
	A waste of resources, but maybe there is a work-around?
*/
data class_copy;
	set class;
run;

proc ds2 ;
	data test(overwrite=yes);
		declare package hash h();
		declare double rc;
		method init();

			if 0 then
				set skeleton_class;
			h.defineKey('name');
			h.defineData('name');
			h.defineData('age');
			h.defineData('sex');
			h.dataset(%tslit({select * from class where sex='F'}));
			h.defineDone();
		end;
		method run();
			set class_copy(keep=(name));
			rc=h.find();

			if rc ne 0 then
				do;
					age=-1;
					sex='X';
				end;
		end;
	enddata;
	run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Produces as a test data set:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="class_output.PNG" style="width: 266px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15458iC6D00934E5CAE0A8/image-size/large?v=v2&amp;amp;px=999" role="button" title="class_output.PNG" alt="class_output.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One thing I've observed with DS2 is that the DECLARE statements need to appear at the top of the method. So this example you gave wouldn't work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;method init(); 
    if 0 then set class (keep=(name age sex)); 
    declare package hash h( [name], [age sex], 16, {select name, age, sex from 
         work.class where sex='F'} );
end; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;, regardless of the other issues, because the hash package declaration appears after the IF statement. That's why I moved it to appear before the init() method. Also I think it needs to be declared outside the methods in order for it to be available to both init() and run().&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 21:14:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Basic-PROC-DS2-Questions/m-p/399255#M96690</guid>
      <dc:creator>anonymous_user</dc:creator>
      <dc:date>2017-09-28T21:14:10Z</dc:date>
    </item>
  </channel>
</rss>

