<?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: SAS Base Query in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Base-Query/m-p/341102#M78016</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17429"&gt;@LaurieF&lt;/a&gt; beat me to it with the exact identical solution.&lt;/P&gt;
&lt;P&gt;I just want to add that&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options missing=0;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;only controls the &lt;U&gt;display&lt;/U&gt; of missing values, the values themselves will stay missing.&lt;/P&gt;</description>
    <pubDate>Wed, 15 Mar 2017 07:59:05 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-03-15T07:59:05Z</dc:date>
    <item>
      <title>SAS Base Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Base-Query/m-p/341096#M78010</link>
      <description>&lt;P&gt;May I know how to get the output from the following input? Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ABC BBC&lt;/P&gt;&lt;P&gt;123&amp;nbsp;&amp;nbsp; 1 &amp;nbsp; &amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;124&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;125&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt; A;&lt;/P&gt;&lt;P&gt;INFILE CARDS;&lt;/P&gt;&lt;P&gt;INPUT ID $ ACCT $;&lt;/P&gt;&lt;P&gt;CARDS;&lt;/P&gt;&lt;P&gt;123 ABC&lt;/P&gt;&lt;P&gt;123 BBC&lt;/P&gt;&lt;P&gt;124 ABC&lt;/P&gt;&lt;P&gt;124 BBC&lt;/P&gt;&lt;P&gt;124 BBC&lt;/P&gt;&lt;P&gt;125 BBC&lt;/P&gt;&lt;P&gt;125 BBC&lt;/P&gt;&lt;P&gt;125 BBC&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 07:27:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Base-Query/m-p/341096#M78010</guid>
      <dc:creator>scb</dc:creator>
      <dc:date>2017-03-15T07:27:08Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Base Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Base-Query/m-p/341099#M78013</link>
      <description>&lt;P&gt;If you iknow&amp;nbsp;that ACCT will always be "ABC" or "BBC" then the programming is pretty straightforward. &amp;nbsp;If necessary to get the data in order, sort first:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;by id;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then calculate:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by id;&lt;/P&gt;
&lt;P&gt;if first.id then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;ABC=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;BBC=0;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;select (ACCT);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;when ("ABC") ABC + 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;when ("BBC") BBC + 1;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;if last.id;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The way the SELECT statement works, it will automatically give you an error if ACCT is neither "ABC" nor "BBC". &amp;nbsp;That can be a blessing or a curse, and can be changed if necessary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you don't know the values of ACCT ahead of time, the result can still be achieved but requires entirely different programming.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 07:47:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Base-Query/m-p/341099#M78013</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-03-15T07:47:46Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Base Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Base-Query/m-p/341100#M78014</link>
      <description>&lt;P&gt;How's this? I've always been a big fan of&amp;nbsp;&lt;EM&gt;proc freq&lt;/EM&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA A;
INFILE CARDS;
INPUT ID $ ACCT $;
CARDS;
123 ABC
123 BBC
124 ABC
124 BBC
124 BBC
125 BBC
125 BBC
125 BBC
;
RUN;

proc freq data=a noprint;
table id * acct / out=want nopercent;
run;

option missing = 0; /* Replaces missing values with - well - zeros */
proc transpose data=want out=want(drop=_name_ _label_);
by id;
id acct;
var count;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Mar 2017 07:53:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Base-Query/m-p/341100#M78014</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-03-15T07:53:48Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Base Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Base-Query/m-p/341102#M78016</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17429"&gt;@LaurieF&lt;/a&gt; beat me to it with the exact identical solution.&lt;/P&gt;
&lt;P&gt;I just want to add that&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options missing=0;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;only controls the &lt;U&gt;display&lt;/U&gt; of missing values, the values themselves will stay missing.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 07:59:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Base-Query/m-p/341102#M78016</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-15T07:59:05Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Base Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Base-Query/m-p/341106#M78018</link>
      <description>&lt;P&gt;Following on from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;, if you must have&amp;nbsp;&lt;EM&gt;0&lt;/EM&gt; and not missing, just tack this on the end:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set want;
array counts[*] _numeric_;
do i = 1 to dim(counts);
   counts[i] = coalesce(counts[i], 0);
   end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Oh, and if your source dataset is huge, the freq may have problems with memory. Ameliorate that with this (assuming that it's already sorted):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=a noprint;
by id;
table acct / out=want nopercent;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The&amp;nbsp;&lt;EM&gt;transpose&lt;/EM&gt; will still do an initial pass through the&amp;nbsp;&lt;EM&gt;freq&lt;/EM&gt; output looking for the distinct values of&amp;nbsp;&lt;EM&gt;acct&lt;/EM&gt; so that it knows how much to rotate,&amp;nbsp;but it's still pretty decent on memory handling.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 08:20:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Base-Query/m-p/341106#M78018</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-03-15T08:20:44Z</dc:date>
    </item>
  </channel>
</rss>

