<?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: dynamic code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648010#M194008</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;simplest would be Proc Tabulate:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input DATE date11. CODE $;
format date date11.;
cards;
10-MAY-2020         G2345
10-MAY-2020          AUTO
11-MAY-2020         G2345
11-MAY-2020          TOP
11-MAY-2020          TOP
;
run;

proc format;
value missingzero
. = 0
other = [best32.]
;
run;
proc tabulate data = have missing;
class date code;
table date, code*n*f=missingzero.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Fri, 15 May 2020 12:41:07 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2020-05-15T12:41:07Z</dc:date>
    <item>
      <title>dynamic code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648001#M194001</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;i have a input data as below&lt;/P&gt;
&lt;P&gt;DATE&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CODE&lt;/P&gt;
&lt;P&gt;10-MAY-2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;G2345&lt;BR /&gt;10-MAY-2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AUTO&lt;BR /&gt;11-MAY-2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;G2345&lt;BR /&gt;11-MAY-2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TOP&lt;BR /&gt;11-MAY-2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TOP&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i need output as like below but the code must be dynamic .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;DATE&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; G2345 TOP AUTO&lt;BR /&gt;10-MAY-2020&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;11-MAY-2020&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;</description>
      <pubDate>Fri, 15 May 2020 12:13:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648001#M194001</guid>
      <dc:creator>rohithverma</dc:creator>
      <dc:date>2020-05-15T12:13:01Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648002#M194002</link>
      <description>&lt;P&gt;Is this for reporting purposes?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 May 2020 12:17:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648002#M194002</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-05-15T12:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648003#M194003</link>
      <description>yes ,automaticallty the output must be creatyed</description>
      <pubDate>Fri, 15 May 2020 12:20:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648003#M194003</guid>
      <dc:creator>rohithverma</dc:creator>
      <dc:date>2020-05-15T12:20:22Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648009#M194007</link>
      <description>&lt;P&gt;Output can be a report file&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;ODS HTML&lt;/LI&gt;
&lt;LI&gt;+ Proc TABULATE&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;or,&amp;nbsp;a data file such as a sas data set&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Proc FREQ&lt;/LI&gt;
&lt;LI&gt;+ TRANSPOSE&lt;/LI&gt;
&lt;LI&gt;+ DATA step clean up&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;data have;
input DATE date11. CODE $; format date date11.; datalines;
10-MAY-2020         G2345
10-MAY-2020          AUTO
11-MAY-2020         G2345
11-MAY-2020          TOP
11-MAY-2020          TOP
;
&lt;BR /&gt;* As a report;
ods html file='output.html' style=plateau;
proc tabulate data=have;
  CLASS DATE CODE;
  TABLE DATE,CODE;
run;&lt;BR /&gt;ods html close;
&lt;BR /&gt;* As a data set;
proc sql;
  create table counts as select date,code,count(*) as N from have group by date,code;
proc transpose data=counts out=stage1(drop=_name_);
  by date;
  id code;
  var N;
run;
data want;
  set stage1;
  array codeN _numeric_;
  do _n_ = 1 to dim(codeN);
    codeN(_n_) = coalesce(codeN(_n_),0);
  end;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 May 2020 12:41:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648009#M194007</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-05-15T12:41:50Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648010#M194008</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;simplest would be Proc Tabulate:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input DATE date11. CODE $;
format date date11.;
cards;
10-MAY-2020         G2345
10-MAY-2020          AUTO
11-MAY-2020         G2345
11-MAY-2020          TOP
11-MAY-2020          TOP
;
run;

proc format;
value missingzero
. = 0
other = [best32.]
;
run;
proc tabulate data = have missing;
class date code;
table date, code*n*f=missingzero.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Fri, 15 May 2020 12:41:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648010#M194008</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-05-15T12:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648011#M194009</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input DATE :date11. CODE $;
format DATE date11.;
datalines;
10-MAY-2020 G2345
10-MAY-2020 AUTO
11-MAY-2020 G2345
11-MAY-2020 TOP
11-MAY-2020 TOP
;

proc tabulate data=have;
    class date code;
    table date,code*n=' ';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Fri, 15 May 2020 12:41:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648011#M194009</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-05-15T12:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648013#M194011</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input DATE  :date11.   CODE $;
format date date11.;
cards;
10-MAY-2020         G2345
10-MAY-2020          AUTO
11-MAY-2020         G2345
11-MAY-2020          TOP
11-MAY-2020          TOP
;

proc freq data=have ;
tables date*code/noprint sparse out=temp(drop=percent);
run;

proc transpose data=temp out=want(drop=_:);
by date;
id code;
var count;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 May 2020 12:44:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648013#M194011</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-05-15T12:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648028#M194018</link>
      <description>I NEED OUPUT LIKE THIS &lt;BR /&gt;&lt;BR /&gt;DATE  		G2345	TOP 	AUTO  TOTAL&lt;BR /&gt;10-MAY-2020	 1	 0	 1     2&lt;BR /&gt;11-MAY-2020	 1	 2	 0     3&lt;BR /&gt;GRANDTOTAL 	 2	 2       1     5</description>
      <pubDate>Fri, 15 May 2020 13:16:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648028#M194018</guid>
      <dc:creator>rohithverma</dc:creator>
      <dc:date>2020-05-15T13:16:57Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648030#M194020</link>
      <description>Sorry but i am unable to generate like below &lt;BR /&gt;&lt;BR /&gt;DATE  		G2345	TOP 	AUTO  TOTAL&lt;BR /&gt;10-MAY-2020	 1	 0	 1     2&lt;BR /&gt;11-MAY-2020	 1	 2	 0     3&lt;BR /&gt;GRANDTOTAL 	 2	 2       1     5</description>
      <pubDate>Fri, 15 May 2020 13:17:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648030#M194020</guid>
      <dc:creator>rohithverma</dc:creator>
      <dc:date>2020-05-15T13:17:20Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648031#M194021</link>
      <description>&lt;P&gt;Use `ALL` keyword:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input DATE date11. CODE $;
format date date11.;
cards;
10-MAY-2020         G2345
10-MAY-2020          AUTO
11-MAY-2020         G2345
11-MAY-2020          TOP
11-MAY-2020          TOP
;
run;

proc format;
value missingzero
. = 0
other = [best32.]
;
run;
proc tabulate data = have missing;
class date code;
table date ALL, (code ALL)*n*f=missingzero.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and read doc abut Proc Tabulate:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=proc&amp;amp;docsetTarget=n00yutbvvckjwrn1ldg5xkvjy1pu.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=proc&amp;amp;docsetTarget=n00yutbvvckjwrn1ldg5xkvjy1pu.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Fri, 15 May 2020 13:20:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648031#M194021</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-05-15T13:20:13Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648032#M194022</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have;
    tables date*code / nopercent norow nocol;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 May 2020 13:20:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648032#M194022</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-05-15T13:20:39Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648042#M194029</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/150852"&gt;@rohithverma&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Sorry but i am unable to generate like below &lt;BR /&gt;&lt;BR /&gt;DATE G2345 TOP AUTO TOTAL&lt;BR /&gt;10-MAY-2020 1 0 1 2&lt;BR /&gt;11-MAY-2020 1 2 0 3&lt;BR /&gt;GRANDTOTAL 2 2 1 5&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Show the exact code that you submitted. Copy from the LOG the entire proc step and any messages that appear in the log. Paste the text into a code box opened on the forum with the &amp;lt;/&amp;gt; icon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 May 2020 14:14:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648042#M194029</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-15T14:14:13Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648096#M194067</link>
      <description>&lt;P&gt;It looks like you are looking for a cross tab. However, prior to that you will need to prep your data for it with an intermediary step. &lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; cursor: text; font-family: inherit; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 1.7142; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;If you just want an output, you can stop with the FREQ. &lt;/SPAN&gt;If you want the output in a dataset, prep one more time before you TRANSPOSE.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data almostHave;
input DATE date11. CODE $ ;
format date date11.;
cards;
10-MAY-2020         G2345 
10-MAY-2020          AUTO 
11-MAY-2020         G2345  
11-MAY-2020          TOP  
11-MAY-2020          TOP  
;
run;

data have ;
   set almostHave ;
   datec = put(date,date11.) ;
   output ;
   datec = "GRANDTOTAL" ;
   output ;
   drop date ;
run ;

ods output crosstabfreqs = ctab ;
proc freq data = have ;
   tables datec * code / sparse ;
run ;
ods output close ;

data wannabe ;
   set ctab ;
   where _type_ in ("10","11") ;
   if code = " " then code = "TOTAL" ;
run ;

proc transpose 
     data = wannabe
     out = want (drop=_:)
     ;
    var frequency ;
    by datec ;
    id code ;
run ;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 May 2020 16:47:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamic-code/m-p/648096#M194067</guid>
      <dc:creator>biopharma</dc:creator>
      <dc:date>2020-05-15T16:47:43Z</dc:date>
    </item>
  </channel>
</rss>

