<?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: SQL query - delete fields according to condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SQL-query-delete-fields-according-to-condition/m-p/929678#M365784</link>
    <description>&lt;P&gt;Don't use PROC SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could just make the report directly from that data you have:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=have;
  columns category type n,month;
  define category / group;
  define type / group;
  define month / across ;
  define n / ' ';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you really want the empty cells to be zeros you might try counting first.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have;
 tables type*category*month / noprint out=counts sparse;
run;

proc report data=counts;
  columns category type count,month;
  define category / group;
  define type / group;
  define month / across;
  define count / ' ';
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want the month numbers to appear as names just make a format and use it.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1716670634919.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96765i6AC2672E0E71E1E9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1716670634919.png" alt="Tom_0-1716670634919.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 25 May 2024 20:57:26 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-05-25T20:57:26Z</dc:date>
    <item>
      <title>SQL query - delete fields according to condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-query-delete-fields-according-to-condition/m-p/929646#M365779</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If I have a program like this that runs every month.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA HAVE;
INPUT CATEGORY$ TYPE MONTH ;
CARDS;

A 100  1
B 200  2 
B 100  3
B 200  1
A 100  2
A 200  1
B 200  1
A 100  1
A 200  2
A 200  3
A 100  5
A 200  9
B 200  10
A 100  1
A 200  11
A 200  11
;
RUN;


PROC SQL;
CREATE TABLE INVENTORY AS
SELECT CATEGORY,
       TYPE,
			 COUNT (CASE WHEN MONTH = 1 THEN TYPE END)   AS JANUARY,
			 COUNT (CASE WHEN MONTH = 2 THEN TYPE END)   AS FEBRUARY,
			 COUNT (CASE WHEN MONTH = 3 THEN TYPE END)   AS MARCH,
			 COUNT (CASE WHEN MONTH = 4 THEN TYPE END)   AS APRIL,
			 COUNT (CASE WHEN MONTH = 5 THEN TYPE END)   AS MAY,
			 COUNT (CASE WHEN MONTH = 6 THEN TYPE END)   AS JUNE,
			 COUNT (CASE WHEN MONTH = 7 THEN TYPE END)   AS JULY,
			 COUNT (CASE WHEN MONTH = 8 THEN TYPE END)   AS AUGUST,
			 COUNT (CASE WHEN MONTH = 9 THEN TYPE END)   AS SEPTEMBER,
			 COUNT (CASE WHEN MONTH = 10 THEN TYPE END)  AS OCTOBER,
			 COUNT (CASE WHEN MONTH = 11 THEN TYPE END)  AS NOVEMBER,
			 COUNT (CASE WHEN MONTH = 12 THEN TYPE END)  AS DECEMBER

			 FROM HAVE
			 GROUP BY CATEGORY, TYPE;
RUN; 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;But I don't want months without data to appear in the report. I want to get this:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MONTH.jpg" style="width: 758px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96761iBF5D46C254BC1434/image-size/large?v=v2&amp;amp;px=999" role="button" title="MONTH.jpg" alt="MONTH.jpg" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;How should I proceed ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2024 21:10:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-query-delete-fields-according-to-condition/m-p/929646#M365779</guid>
      <dc:creator>sasuser_8</dc:creator>
      <dc:date>2024-05-24T21:10:04Z</dc:date>
    </item>
    <item>
      <title>Re: SQL query - delete fields according to condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-query-delete-fields-according-to-condition/m-p/929650#M365780</link>
      <description>&lt;P&gt;Looks like a report, so&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value myfmt
  1 = "January"
  ...
  12 = "December"
;
run;

proc report data=have;
column category type n,month;
define category / group;
define type / group;
define n / "";
define month / "" across format=myfmt.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2024 22:11:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-query-delete-fields-according-to-condition/m-p/929650#M365780</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-05-24T22:11:52Z</dc:date>
    </item>
    <item>
      <title>Re: SQL query - delete fields according to condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-query-delete-fields-according-to-condition/m-p/929652#M365781</link>
      <description>&lt;P&gt;My take:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
value mymonth
1 = 'JANUARY'
2 = 'FEBRUARY'
3 = 'MARCH'
4 = 'APRIL'
5 = 'MAY'
6 = 'JUNE'
7 = 'JULY'
8 = 'AUGUST'
9 = 'SEPTEMBER'
10 = 'OCTOBER'
11 = 'NOVEMBER'
12 = 'DECEMBER'
;
run;



proc report data=have;
   columns category type n,month;
   define category/group;
   define type /group;
   define month/across '' order=internal format=mymonth.;&lt;BR /&gt;   define n /'';
run;
&lt;/PRE&gt;
&lt;P&gt;if you really want 0's in the body then set OPTIONS MISSING='0'; before proc report.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you had an actual DATE value instead of some random numbers like 1, 2, 3 then the SAS supplied MONNAME would be the format to use for this report.&lt;/P&gt;
&lt;P&gt;Or Proc tabulate which will have a slightly difference appearance:&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=have;
   class category type month;
   format month mymonth.;
   table category*type,
         month='' *n=''
         /misstext='0'
   ;
run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And a very good reason to use formats instead of variables: Change the format, use it in the report with the SAME DATA SET.&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
value halfyear_qtr
1,2,3,4,5,6 = 'Jan-Jun'
7,8,9 = 'Jul-Sep'
10 = 'OCTOBER'
11 = 'NOVEMBER'
12 = 'DECEMBER'
;
run;
proc report data=have;
   columns category type n,month;
   define category/group;
   define type /group;
   define month/across '' order=internal format=halfyear_qtr.;
   define n/'' ;
run;&lt;/PRE&gt;
&lt;P&gt;If a value to display in a report is based on a single variable then a custom format is quite often much easier to write, is more flexible, easier to change ( I have some formats with over 100 location codes for example that change adding one or two every few months). Instead of having to update hundreds of lines of IF/THEN/ELSE or worse yet CASE/WHEN code all I have to do is add 1234='New name' to the format, run the format definition program code and then the report updates based on the values.&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2024 22:42:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-query-delete-fields-according-to-condition/m-p/929652#M365781</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-05-24T22:42:19Z</dc:date>
    </item>
    <item>
      <title>Re: SQL query - delete fields according to condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-query-delete-fields-according-to-condition/m-p/929678#M365784</link>
      <description>&lt;P&gt;Don't use PROC SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could just make the report directly from that data you have:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=have;
  columns category type n,month;
  define category / group;
  define type / group;
  define month / across ;
  define n / ' ';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you really want the empty cells to be zeros you might try counting first.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have;
 tables type*category*month / noprint out=counts sparse;
run;

proc report data=counts;
  columns category type count,month;
  define category / group;
  define type / group;
  define month / across;
  define count / ' ';
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want the month numbers to appear as names just make a format and use it.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1716670634919.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96765i6AC2672E0E71E1E9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1716670634919.png" alt="Tom_0-1716670634919.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 May 2024 20:57:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-query-delete-fields-according-to-condition/m-p/929678#M365784</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-05-25T20:57:26Z</dc:date>
    </item>
    <item>
      <title>Re: SQL query - delete fields according to condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-query-delete-fields-according-to-condition/m-p/929859#M365842</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Thanks !&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 May 2024 22:02:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-query-delete-fields-according-to-condition/m-p/929859#M365842</guid>
      <dc:creator>sasuser_8</dc:creator>
      <dc:date>2024-05-27T22:02:14Z</dc:date>
    </item>
  </channel>
</rss>

