<?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 sql to sas in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/sql-to-sas/m-p/681167#M24023</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know easily how to do this code in Sql but how to do this count and case when&amp;nbsp; on SAS statement?&lt;/P&gt;&lt;P&gt;Could someone give me some help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sql code:&lt;/P&gt;&lt;P&gt;Select count( subscr_id) as qty,&lt;BR /&gt;Case when m3_topup_index =0 THEN 'a.Zero'&lt;BR /&gt;when m3_topup_index &amp;gt; 0 and m3_topup_index&amp;lt;=0.5 THEN 'b.0-0.5'&lt;BR /&gt;when m3_topup_index &amp;gt; 0.5 and m3_topup_index&amp;lt;=1 THEN 'c.0.5-1'&lt;BR /&gt;when m3_topup_index &amp;gt; 1 and m3_topup_index&amp;lt;=1.5 THEN 'd.1- 1.5'&lt;BR /&gt;when m3_topup_index &amp;gt; 1.5 and m3_topup_index&amp;lt;=2.0 THEN 'e.1.5-2.0'&lt;BR /&gt;when m3_topup_index &amp;gt; 2.0 THEN 'f.Above 2.0'&lt;BR /&gt;else 'g.Other'&lt;BR /&gt;end as m3_topup_index_grp&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* The variable m3_topup_index_grp&amp;nbsp; is not on my&amp;nbsp; SAS dataset.&lt;/P&gt;&lt;P&gt;So how do I create it&amp;nbsp; as I only&amp;nbsp; have the variable m3_topu_index */&lt;/P&gt;&lt;P&gt;from ptwopperfs_1_may20&amp;nbsp; /* my sas dataset*/&lt;BR /&gt;group by subscr_id&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried this on SAS but is not correct:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc summary data=perfmoni.ptwopperfs_1_may20 nway;&lt;/P&gt;&lt;P&gt;var m3_topup_index;&lt;/P&gt;&lt;P&gt;output out=want (drop=_:)&lt;/P&gt;&lt;P&gt;n=count_subscr_id&lt;BR /&gt;sum=sum_m3_topup_index;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Wed, 02 Sep 2020 22:11:33 GMT</pubDate>
    <dc:creator>jorquec</dc:creator>
    <dc:date>2020-09-02T22:11:33Z</dc:date>
    <item>
      <title>sql to sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/sql-to-sas/m-p/681167#M24023</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know easily how to do this code in Sql but how to do this count and case when&amp;nbsp; on SAS statement?&lt;/P&gt;&lt;P&gt;Could someone give me some help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sql code:&lt;/P&gt;&lt;P&gt;Select count( subscr_id) as qty,&lt;BR /&gt;Case when m3_topup_index =0 THEN 'a.Zero'&lt;BR /&gt;when m3_topup_index &amp;gt; 0 and m3_topup_index&amp;lt;=0.5 THEN 'b.0-0.5'&lt;BR /&gt;when m3_topup_index &amp;gt; 0.5 and m3_topup_index&amp;lt;=1 THEN 'c.0.5-1'&lt;BR /&gt;when m3_topup_index &amp;gt; 1 and m3_topup_index&amp;lt;=1.5 THEN 'd.1- 1.5'&lt;BR /&gt;when m3_topup_index &amp;gt; 1.5 and m3_topup_index&amp;lt;=2.0 THEN 'e.1.5-2.0'&lt;BR /&gt;when m3_topup_index &amp;gt; 2.0 THEN 'f.Above 2.0'&lt;BR /&gt;else 'g.Other'&lt;BR /&gt;end as m3_topup_index_grp&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* The variable m3_topup_index_grp&amp;nbsp; is not on my&amp;nbsp; SAS dataset.&lt;/P&gt;&lt;P&gt;So how do I create it&amp;nbsp; as I only&amp;nbsp; have the variable m3_topu_index */&lt;/P&gt;&lt;P&gt;from ptwopperfs_1_may20&amp;nbsp; /* my sas dataset*/&lt;BR /&gt;group by subscr_id&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried this on SAS but is not correct:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc summary data=perfmoni.ptwopperfs_1_may20 nway;&lt;/P&gt;&lt;P&gt;var m3_topup_index;&lt;/P&gt;&lt;P&gt;output out=want (drop=_:)&lt;/P&gt;&lt;P&gt;n=count_subscr_id&lt;BR /&gt;sum=sum_m3_topup_index;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 22:11:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/sql-to-sas/m-p/681167#M24023</guid>
      <dc:creator>jorquec</dc:creator>
      <dc:date>2020-09-02T22:11:33Z</dc:date>
    </item>
    <item>
      <title>Re: sql to sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/sql-to-sas/m-p/681173#M24024</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/270435"&gt;@jorquec&lt;/a&gt;&amp;nbsp; Please take a look at &lt;STRONG&gt;"Proc Format"&lt;/STRONG&gt; to defne the ranges and the associated labels for the ranges. Then apply/call the format in &lt;STRONG&gt;"Proc Summary".&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 22:48:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/sql-to-sas/m-p/681173#M24024</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-09-02T22:48:41Z</dc:date>
    </item>
    <item>
      <title>Re: sql to sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/sql-to-sas/m-p/681347#M24027</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for the tip!&lt;/P&gt;&lt;P&gt;Could you please tell me how to add now an additional information of the frequency but in percentage ?&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* step1*/
DATA work.counts;
set perfmoni.ptwopperfs_1_may20;

length m3_topup_index_grp $ 30;
format m3_topup_index_grp  $char.;

If m3_topup_index =0 THEN m3_topup_index_grp='a.Zero';
else if m3_topup_index &amp;gt; 0 and  m3_topup_index&amp;lt;=0.5  THEN m3_topup_index_grp= 'b.0-0.5';
else if m3_topup_index &amp;gt; 0.5 and  m3_topup_index&amp;lt;=1  THEN m3_topup_index_grp='c.0.5-1';
else if m3_topup_index &amp;gt; 1 and  m3_topup_index&amp;lt;=1.5  THEN m3_topup_index_grp= 'd.1- 1.5';
else if m3_topup_index &amp;gt; 1.5 and  m3_topup_index&amp;lt;=2.0  THEN m3_topup_index_grp= 'e.1.5-2.0';
else if m3_topup_index &amp;gt; 2.0 THEN m3_topup_index_grp= 'f.Above 2.0';
else  m3_topup_index_grp= 'g.Other';
run;

/* step 2*/
proc summary data=work.counts ;
types m3_topup_index_grp ;   
  class m3_topup_index_grp ;
  var   subscr_id;
  output out=total_subscrid n(subscr_id)= 
        / autoname autolabel;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Sep 2020 14:07:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/sql-to-sas/m-p/681347#M24027</guid>
      <dc:creator>jorquec</dc:creator>
      <dc:date>2020-09-03T14:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: sql to sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/sql-to-sas/m-p/681349#M24028</link>
      <description>&lt;P&gt;I would use a format, then you don't need to modify your data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
  value index_grp 
        0 = 'a.Zero'
   0&amp;lt;-0.5 = 'b.0-0.5'
   0.5&amp;lt;-1 = 'c.0.5-1'
   1&amp;lt;-1.5 = 'd.1- 1.5'
   1.5&amp;lt;-2 = 'e.1.5-2.0'
  2&amp;lt;-high = 'f.Above 2.0'
    other = 'g.Other'
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To get count and percent use PROC FREQ.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=ptwopperfs_1_may20 ;
  tables m3_topup_index / missing;
  format m3_topup_index index_grp. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to eliminate the observations with missing values of&amp;nbsp;&lt;SPAN&gt;subscr_id like the COUNT(subscr_id) aggregate function in SQL will do then add a where statement.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where not missing(subscr_id);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Sep 2020 14:26:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/sql-to-sas/m-p/681349#M24028</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-09-03T14:26:03Z</dc:date>
    </item>
    <item>
      <title>Re: sql to sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/sql-to-sas/m-p/681634#M24046</link>
      <description>&lt;P&gt;Thanks so much! Great.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Sep 2020 13:50:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/sql-to-sas/m-p/681634#M24046</guid>
      <dc:creator>jorquec</dc:creator>
      <dc:date>2020-09-04T13:50:14Z</dc:date>
    </item>
  </channel>
</rss>

