<?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: proc sql  to data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-to-data-step/m-p/548588#M152134</link>
    <description>Thanks so how would i rewite the above code in the data step&lt;BR /&gt;</description>
    <pubDate>Thu, 04 Apr 2019 17:45:22 GMT</pubDate>
    <dc:creator>Ranjeeta</dc:creator>
    <dc:date>2019-04-04T17:45:22Z</dc:date>
    <item>
      <title>proc sql  to data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-to-data-step/m-p/548582#M152129</link>
      <description>&lt;P&gt;I am getting an error in the data step but not proc sql what am i doing wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table icd as&lt;BR /&gt;select distinct key_enc from&lt;BR /&gt;pa.dad_px_all&lt;BR /&gt;where key_enc in (select key_enc from pa.dad_px_all&lt;BR /&gt;where px in ('I210', 'I211'))&lt;BR /&gt;;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data icd ;&lt;/P&gt;&lt;P&gt;set pa.dad_px_all;&lt;/P&gt;&lt;P&gt;where px in ('I210', 'I211');&lt;/P&gt;&lt;P&gt;if first.key_enc and last.key_enc;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 17:31:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-to-data-step/m-p/548582#M152129</guid>
      <dc:creator>Ranjeeta</dc:creator>
      <dc:date>2019-04-04T17:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql  to data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-to-data-step/m-p/548586#M152131</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/240770"&gt;@Ranjeeta&lt;/a&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am afraid if you happen to think&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if first.key_enc and last.key_enc;&amp;nbsp; &amp;nbsp; /*this picks only the &lt;STRONG&gt;unique&lt;/STRONG&gt; occurrence*/&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;is an equivalent to&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;select distinct key_enc from&amp;nbsp;&amp;nbsp;&amp;nbsp; /*this picks only &lt;STRONG&gt;one&lt;/STRONG&gt; occurrence of each key from multiples or unique*/&lt;BR /&gt;pa.dad_px_all&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;your understanding is incorrect. Anyways, can you post a sample of what you HAVE and WANT so that we can provide you with the correct&amp;nbsp;&lt;/SPAN&gt;solution&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 17:39:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-to-data-step/m-p/548586#M152131</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-04T17:39:35Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql  to data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-to-data-step/m-p/548588#M152134</link>
      <description>Thanks so how would i rewite the above code in the data step&lt;BR /&gt;</description>
      <pubDate>Thu, 04 Apr 2019 17:45:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-to-data-step/m-p/548588#M152134</guid>
      <dc:creator>Ranjeeta</dc:creator>
      <dc:date>2019-04-04T17:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql  to data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-to-data-step/m-p/548590#M152135</link>
      <description>&lt;P&gt;data icd ;&lt;/P&gt;
&lt;P&gt;set pa.dad_px_all;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;by&amp;nbsp;key_enc ;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;where px in ('I210', 'I211');&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;if first.key_enc ;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See the &lt;EM&gt;&lt;STRONG&gt;bold&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make sure your&amp;nbsp;pa.dad_px_all is &lt;EM&gt;&lt;STRONG&gt;sorted by&amp;nbsp;by&amp;nbsp;key_enc ;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 17:47:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-to-data-step/m-p/548590#M152135</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-04T17:47:29Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql  to data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-to-data-step/m-p/548594#M152139</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/240770"&gt;@Ranjeeta&lt;/a&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am afraid if you happen to think&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if first.key_enc and last.key_enc;&amp;nbsp; &amp;nbsp; /*this picks only the &lt;STRONG&gt;unique&lt;/STRONG&gt; occurrence*/&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;is an equivalent to&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;select distinct key_enc from&amp;nbsp;&amp;nbsp;&amp;nbsp; /*this picks only &lt;STRONG&gt;one&lt;/STRONG&gt; occurrence of each key from multiples or unique*/&lt;BR /&gt;pa.dad_px_all&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;your understanding is incorrect. Anyways, can you post a sample of what you HAVE and WANT so that we can provide you with the correct&amp;nbsp;&lt;/SPAN&gt;solution&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since the final results is only the ID, it doesn't matter here, but does in general&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 17:49:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-to-data-step/m-p/548594#M152139</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-04-04T17:49:06Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql  to data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-to-data-step/m-p/548595#M152140</link>
      <description>&lt;P&gt;Then plz explain this difference in the results&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input transaction_id;
cards;
1
1
1
1
2
2
3
;

proc sql;
create table want_sql as
select distinct transaction_id
from have;
quit;

data want_datastep;
set have;
by transaction_id;
if first.transaction_id and last.transaction_id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 17:54:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-to-data-step/m-p/548595#M152140</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-04T17:54:08Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql  to data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-to-data-step/m-p/548598#M152142</link>
      <description>&lt;P&gt;Thanks This makes it very clear&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 17:59:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-to-data-step/m-p/548598#M152142</guid>
      <dc:creator>Ranjeeta</dc:creator>
      <dc:date>2019-04-04T17:59:19Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql  to data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-to-data-step/m-p/548599#M152143</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/240770"&gt;@Ranjeeta&lt;/a&gt;&amp;nbsp; &amp;nbsp;I had a similar misunderstanding too. The person who corrected me was&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp; who picked a nit in mine when&amp;nbsp; my understanding wasn't clear and I posted a rather incorrect solution stressing that was right. Well Mark has helped me correct and taught me tons in the past but he doesn't seem to do that lately. Probably had enough of me&amp;nbsp; Haha lol&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ok furthermore,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select distinct does an &lt;STRONG&gt;implicit sort&lt;/STRONG&gt; and picks one&lt;/P&gt;
&lt;P&gt;so using select distinct with an unsorted below&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input transaction_id;&lt;BR /&gt;cards;&lt;BR /&gt;1&lt;BR /&gt;1&lt;BR /&gt;1&lt;BR /&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;6&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;6&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;BR /&gt;2&lt;BR /&gt;3&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;would result in &lt;STRONG&gt;sorted output&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So basically the SQL processor does an implicit sort and picks each unique key whereas the above sample would require a &lt;STRONG&gt;presort &lt;/STRONG&gt;for the datastep compiler to execute. So lazy happy go lucky folks like me prefer proc sql unless a datastep is warranted. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&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;</description>
      <pubDate>Thu, 04 Apr 2019 18:07:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-to-data-step/m-p/548599#M152143</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-04T18:07:56Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql  to data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-to-data-step/m-p/548602#M152145</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp; I think I understand what you're trying to say and I didn't the first time. I guess unique doesn't equal 'single' to me but that technical definition is correct, records are unique or duplicate and in this case OP wants a list of unique keys. Can you tell I'm spending too much time on writing now?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can find a list of unique keys using PROC SORT, SQL or Data step can accomplish.&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>Thu, 04 Apr 2019 18:10:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-to-data-step/m-p/548602#M152145</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-04-04T18:10:16Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql  to data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-to-data-step/m-p/548606#M152147</link>
      <description>&lt;P&gt;Oh well, it's no biggie and trivial to somebody of your experience and expertise where the communication misunderstanding happens too often as sometimes there is lack of clarity.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was going at length for the benefit of new folks and certainly not you et al. If I didn't the Gentle giant Ballardw would hahaha. I didn;t want to give him a chance&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 18:16:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-to-data-step/m-p/548606#M152147</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-04T18:16:46Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql  to data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-to-data-step/m-p/548609#M152148</link>
      <description>&lt;P&gt;If you want to avoid presort or implicit sort assuming the output order doesn't matter, hash is a good idea&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input transaction_id;
cards;
1
1
1
1
6
6
2
2
3
;

data _null_;
dcl hash h(dataset:'have');
   h.definekey  ("transaction_id") ;
   h.definedata ("transaction_id") ;
   h.definedone () ;
h.output(dataset:'want');
stop;
set have;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Apr 2019 18:20:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-to-data-step/m-p/548609#M152148</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-04T18:20:20Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql  to data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-to-data-step/m-p/548621#M152153</link>
      <description>&lt;P&gt;And mere &lt;STRONG&gt;sort&lt;/STRONG&gt; and &lt;STRONG&gt;nodupkey&lt;/STRONG&gt; should do just fine&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sort data=pa.dad_px_all(where=(px in ('I210', 'I211')))  out=icd  nodupkey;
by key_enc ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Apr 2019 18:44:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-to-data-step/m-p/548621#M152153</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-04T18:44:08Z</dc:date>
    </item>
  </channel>
</rss>

