<?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: column filter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/column-filter/m-p/226823#M40847</link>
    <description>&lt;P&gt;Here is a crude attempt to transpose my dataset. Looking for better alternatives. The "crap" field is a fix I read in a SUGI paper while dealing with both numeric and character variables while transposing. I actually dont need the crap field but I have to put it because I dont want the formats to get lost while transposing.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table mthly_sumry as&lt;BR /&gt;select country,&lt;BR /&gt;product,&lt;BR /&gt;month,&lt;BR /&gt;/*sum( '$ SPENT'n) as sum_pln_spent, */&lt;BR /&gt;sum('Actual GRPs'n) as actual_grp format=comma20.,&lt;BR /&gt;sum('Actual IMPs'n) as actual_imp format=comma20.,&lt;BR /&gt;sum('Actual Spend'n) as actual_spend format=dollar20.2 ,&lt;BR /&gt;sum('Buy Now'n) as buynow,&lt;BR /&gt;/*sum('Cl. Spots'n) as sum_clspot,*/&lt;BR /&gt;/*sum(Coupons),*/&lt;BR /&gt;/*sum(Date Aired),*/&lt;BR /&gt;sum('Planned GRPs'n) as planned_grp format=comma20.,&lt;BR /&gt;sum('Planned IMPs'n) as pln_imp format=comma20.,&lt;BR /&gt;sum('Planned Spend'n) as pln_spend format=dollar20.2,&lt;BR /&gt;/*sum(Store),*/&lt;BR /&gt;/*sum(Test) ,*/&lt;BR /&gt;sum('VIS To BLU'n) as visits,&lt;BR /&gt;(calculated actual_spend)/(calculated pln_spend) as spend_clearance format=percent10.2,&lt;BR /&gt;(calculated actual_imp)/(calculated pln_imp) as imp_clearance format=percent10.2,&lt;BR /&gt;(calculated actual_spend)/( calculated visits) as cpv&lt;BR /&gt;/*sum(W25-54IMP),*/&lt;BR /&gt;/*sum(W25-54RTG)*/&lt;BR /&gt;from lasrlib.bb_may2015&lt;BR /&gt;group by country,product,month;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select&lt;BR /&gt;count(distinct month) as cntmth into :cnt_bb_dist_mth&lt;BR /&gt;from lasrlib.bb_may2015;&lt;BR /&gt;quit;&lt;BR /&gt;%let cnt_bb_dist_mth_trm=%CMPRES(&amp;amp;cnt_bb_dist_mth);&lt;BR /&gt;%put "the number of distinct weeks in compressed format: &amp;amp;cnt_bb_dist_mth.";&lt;BR /&gt;proc sql;&lt;BR /&gt;select distinct month as month into :bb_mths1-:bb_mths&amp;amp;cnt_bb_dist_mth_trm.&lt;BR /&gt;from lasrlib.bb_may2015&lt;BR /&gt;order by month&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;run;&lt;BR /&gt;%put "&amp;amp;bb_mths1-&amp;amp;&amp;amp;bb_mths&amp;amp;cnt_bb_dist_mth_trm.";&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Data basedataset;&lt;BR /&gt;run;&lt;BR /&gt;%macro _loopthrumths;&lt;BR /&gt;%do i = 1 %to &amp;amp;cnt_bb_dist_mth_trm;&lt;BR /&gt;%put &amp;amp;&amp;amp;bb_mths&amp;amp;i.;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table month&amp;amp;&amp;amp;bb_mths&amp;amp;i. as&lt;BR /&gt;select * from mthly_sumry&lt;BR /&gt;where upcase(month)=upcase("&amp;amp;&amp;amp;bb_mths&amp;amp;i.")&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;data tmp_month&amp;amp;&amp;amp;bb_mths&amp;amp;i.;&lt;BR /&gt;set month&amp;amp;&amp;amp;bb_mths&amp;amp;i.;&lt;BR /&gt;month_filter=month;&lt;BR /&gt;crap="crap";&lt;BR /&gt;run;&lt;BR /&gt;proc sort data= tmp_month&amp;amp;&amp;amp;bb_mths&amp;amp;i.;&lt;BR /&gt;by country product month_filter;&lt;BR /&gt;run;&lt;BR /&gt;proc transpose data=tmp_month&amp;amp;&amp;amp;bb_mths&amp;amp;i. out=mthly_smry_&amp;amp;i._tr (rename=(_name_=metric) ) ;&lt;BR /&gt;by country product month_filter;&lt;BR /&gt;id month;&lt;BR /&gt;var actual_grp&lt;BR /&gt;actual_imp&lt;BR /&gt;actual_spend&lt;BR /&gt;buynow&lt;BR /&gt;planned_grp&lt;BR /&gt;pln_imp&lt;BR /&gt;pln_spend&lt;BR /&gt;visits&lt;BR /&gt;crap&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;data basedataset (drop=crap);&lt;BR /&gt;set basedataset&lt;BR /&gt;mthly_smry_&amp;amp;i._tr&lt;BR /&gt;;&lt;BR /&gt;if metric in ('crap'," ",'') then delete;&lt;BR /&gt;Metric=upcase(TRANWRD(metric,"_"," "));&lt;BR /&gt;run;&lt;BR /&gt;proc sql;&lt;BR /&gt;create view monthly_smry_final as&lt;BR /&gt;select * from basedataset&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;%mend _loopthrumths;&lt;BR /&gt;%_loopthrumths&lt;BR /&gt;/* Drop existing table */&lt;BR /&gt;%vdb_dt(LASRLIB.LSR_BBMAY2015_MTHSMRY_TR);&lt;BR /&gt;data LASRLIB.LSR_BBMAY2015_MTHSMRY_TR ( );&lt;BR /&gt;set monthly_smry_final ( );&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Tue, 22 Sep 2015 22:05:51 GMT</pubDate>
    <dc:creator>saspert</dc:creator>
    <dc:date>2015-09-22T22:05:51Z</dc:date>
    <item>
      <title>column filter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/column-filter/m-p/225401#M40456</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am transposing a dataset with column names set to "week of 1/1/2015", "week of 8/1/2015" and so on. Now I need a column based filter in SAS VA 7.1 LASR dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;week1&lt;/TD&gt;&lt;TD&gt;week1&lt;/TD&gt;&lt;TD&gt;week1&lt;/TD&gt;&lt;TD&gt;week2&lt;/TD&gt;&lt;TD&gt;week2&lt;/TD&gt;&lt;TD&gt;week2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;week1&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;week1&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;week1&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;week2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;week2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;week2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At worst, I will be stuck with emplty columns which is ok with me. Any ideas how do I get it done?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;saspert&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2015 16:56:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/column-filter/m-p/225401#M40456</guid>
      <dc:creator>saspert</dc:creator>
      <dc:date>2015-09-14T16:56:52Z</dc:date>
    </item>
    <item>
      <title>Re: column filter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/column-filter/m-p/225495#M40481</link>
      <description>Could you please provide a sample data and the expected output to get a better solution&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Jag</description>
      <pubDate>Tue, 15 Sep 2015 01:07:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/column-filter/m-p/225495#M40481</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2015-09-15T01:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: column filter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/column-filter/m-p/226823#M40847</link>
      <description>&lt;P&gt;Here is a crude attempt to transpose my dataset. Looking for better alternatives. The "crap" field is a fix I read in a SUGI paper while dealing with both numeric and character variables while transposing. I actually dont need the crap field but I have to put it because I dont want the formats to get lost while transposing.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table mthly_sumry as&lt;BR /&gt;select country,&lt;BR /&gt;product,&lt;BR /&gt;month,&lt;BR /&gt;/*sum( '$ SPENT'n) as sum_pln_spent, */&lt;BR /&gt;sum('Actual GRPs'n) as actual_grp format=comma20.,&lt;BR /&gt;sum('Actual IMPs'n) as actual_imp format=comma20.,&lt;BR /&gt;sum('Actual Spend'n) as actual_spend format=dollar20.2 ,&lt;BR /&gt;sum('Buy Now'n) as buynow,&lt;BR /&gt;/*sum('Cl. Spots'n) as sum_clspot,*/&lt;BR /&gt;/*sum(Coupons),*/&lt;BR /&gt;/*sum(Date Aired),*/&lt;BR /&gt;sum('Planned GRPs'n) as planned_grp format=comma20.,&lt;BR /&gt;sum('Planned IMPs'n) as pln_imp format=comma20.,&lt;BR /&gt;sum('Planned Spend'n) as pln_spend format=dollar20.2,&lt;BR /&gt;/*sum(Store),*/&lt;BR /&gt;/*sum(Test) ,*/&lt;BR /&gt;sum('VIS To BLU'n) as visits,&lt;BR /&gt;(calculated actual_spend)/(calculated pln_spend) as spend_clearance format=percent10.2,&lt;BR /&gt;(calculated actual_imp)/(calculated pln_imp) as imp_clearance format=percent10.2,&lt;BR /&gt;(calculated actual_spend)/( calculated visits) as cpv&lt;BR /&gt;/*sum(W25-54IMP),*/&lt;BR /&gt;/*sum(W25-54RTG)*/&lt;BR /&gt;from lasrlib.bb_may2015&lt;BR /&gt;group by country,product,month;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select&lt;BR /&gt;count(distinct month) as cntmth into :cnt_bb_dist_mth&lt;BR /&gt;from lasrlib.bb_may2015;&lt;BR /&gt;quit;&lt;BR /&gt;%let cnt_bb_dist_mth_trm=%CMPRES(&amp;amp;cnt_bb_dist_mth);&lt;BR /&gt;%put "the number of distinct weeks in compressed format: &amp;amp;cnt_bb_dist_mth.";&lt;BR /&gt;proc sql;&lt;BR /&gt;select distinct month as month into :bb_mths1-:bb_mths&amp;amp;cnt_bb_dist_mth_trm.&lt;BR /&gt;from lasrlib.bb_may2015&lt;BR /&gt;order by month&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;run;&lt;BR /&gt;%put "&amp;amp;bb_mths1-&amp;amp;&amp;amp;bb_mths&amp;amp;cnt_bb_dist_mth_trm.";&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Data basedataset;&lt;BR /&gt;run;&lt;BR /&gt;%macro _loopthrumths;&lt;BR /&gt;%do i = 1 %to &amp;amp;cnt_bb_dist_mth_trm;&lt;BR /&gt;%put &amp;amp;&amp;amp;bb_mths&amp;amp;i.;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table month&amp;amp;&amp;amp;bb_mths&amp;amp;i. as&lt;BR /&gt;select * from mthly_sumry&lt;BR /&gt;where upcase(month)=upcase("&amp;amp;&amp;amp;bb_mths&amp;amp;i.")&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;data tmp_month&amp;amp;&amp;amp;bb_mths&amp;amp;i.;&lt;BR /&gt;set month&amp;amp;&amp;amp;bb_mths&amp;amp;i.;&lt;BR /&gt;month_filter=month;&lt;BR /&gt;crap="crap";&lt;BR /&gt;run;&lt;BR /&gt;proc sort data= tmp_month&amp;amp;&amp;amp;bb_mths&amp;amp;i.;&lt;BR /&gt;by country product month_filter;&lt;BR /&gt;run;&lt;BR /&gt;proc transpose data=tmp_month&amp;amp;&amp;amp;bb_mths&amp;amp;i. out=mthly_smry_&amp;amp;i._tr (rename=(_name_=metric) ) ;&lt;BR /&gt;by country product month_filter;&lt;BR /&gt;id month;&lt;BR /&gt;var actual_grp&lt;BR /&gt;actual_imp&lt;BR /&gt;actual_spend&lt;BR /&gt;buynow&lt;BR /&gt;planned_grp&lt;BR /&gt;pln_imp&lt;BR /&gt;pln_spend&lt;BR /&gt;visits&lt;BR /&gt;crap&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;data basedataset (drop=crap);&lt;BR /&gt;set basedataset&lt;BR /&gt;mthly_smry_&amp;amp;i._tr&lt;BR /&gt;;&lt;BR /&gt;if metric in ('crap'," ",'') then delete;&lt;BR /&gt;Metric=upcase(TRANWRD(metric,"_"," "));&lt;BR /&gt;run;&lt;BR /&gt;proc sql;&lt;BR /&gt;create view monthly_smry_final as&lt;BR /&gt;select * from basedataset&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;%mend _loopthrumths;&lt;BR /&gt;%_loopthrumths&lt;BR /&gt;/* Drop existing table */&lt;BR /&gt;%vdb_dt(LASRLIB.LSR_BBMAY2015_MTHSMRY_TR);&lt;BR /&gt;data LASRLIB.LSR_BBMAY2015_MTHSMRY_TR ( );&lt;BR /&gt;set monthly_smry_final ( );&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2015 22:05:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/column-filter/m-p/226823#M40847</guid>
      <dc:creator>saspert</dc:creator>
      <dc:date>2015-09-22T22:05:51Z</dc:date>
    </item>
  </channel>
</rss>

