<?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: Seeking help for SAS code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Seeking-help-for-SAS-code/m-p/232400#M268114</link>
    <description>&lt;P&gt;Something like the below, note that it is not optimal coding, it is more to describe the thinking behind it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
  informat date date9.;
  input Shop_id Date;
datalines;
1 23MAR2015
1 01APR2015
2 01MAR2015
2 01MAY2015
;
run;

data have2;
  informat date date9.;
  input Shop_id Date Cust_id Gender;
datalines;
1 01MAR2015 113 1
1 01APR2015 115 0
2 03MAR2015 116 1
;
run;

proc sql;
  create table WANT as
  select  distinct  SHOP_ID
                    ,DATE
                    ,count(CUST_ID) as RESULT
  from  (select A.*
                ,B.CUST_ID
         from   HAVE1 A
         left join (select * from HAVE2 where GENDER=1) B
         on     A.SHOP_ID=B.SHOP_ID
         and    intnx('month',A.DATE,-1) &amp;lt;= B.DATE &amp;lt;= A.DATE)
  group by SHOP_ID,DATE;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Ok, so in the subquery, the from (), I join all female records back to the main dataset based on date being between date-1 month and date. &amp;nbsp;Then in the main query I count these using a by group.&lt;/P&gt;</description>
    <pubDate>Fri, 30 Oct 2015 10:38:52 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2015-10-30T10:38:52Z</dc:date>
    <item>
      <title>Seeking help for SAS code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Seeking-help-for-SAS-code/m-p/232380#M268113</link>
      <description>&lt;P&gt;Hi all&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to find the number of females who have entered the shop within the past month with the data I have. I have written the code but somehow it doesn't seem to work. Your help is greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me describe my data. I have 2 datasets:&lt;/P&gt;&lt;P&gt;Data1: this data has the shop id and date &amp;nbsp;and looks something like this&lt;/P&gt;&lt;P&gt;Shop_id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Date&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;23/3/2015&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1/4/2015&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1/3/2015&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/5/2015&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data2: this data has the shop id, the date of customer visits, the customer id and the gender of customer (0 for male and 1 for female)&lt;/P&gt;&lt;P&gt;Shop_id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Date &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Cust_id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Gender&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/3/2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 113 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/4/2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 115 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3/3/2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 116 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a new dataset, data3, which has the shop_id, the date and the number of female customers who have visited the shop in the past 1 month (prior to the date). For example, in row 1, i want to insert a new column, no_female, which is the number of females who have visited the shop 1 from 23/2/2015 to 22/3/2015.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the code I write, but it doesn't seem to work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc sql;&lt;/P&gt;&lt;P&gt;Create table data3 as&lt;/P&gt;&lt;P&gt;Select a.*,sum(b.gender) as no_female&lt;/P&gt;&lt;P&gt;from data1 as a, data2 as b&lt;/P&gt;&lt;P&gt;where a.shop_id = b.shop_id and -30 &amp;lt;= intck('day',a.date,b.date) &amp;lt; 0&lt;/P&gt;&lt;P&gt;group by a.shop_id, a.date;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your help is greatly appreciated!! Thanks!!!&lt;/P&gt;</description>
      <pubDate>Fri, 30 Oct 2015 07:16:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Seeking-help-for-SAS-code/m-p/232380#M268113</guid>
      <dc:creator>Truc</dc:creator>
      <dc:date>2015-10-30T07:16:10Z</dc:date>
    </item>
    <item>
      <title>Re: Seeking help for SAS code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Seeking-help-for-SAS-code/m-p/232400#M268114</link>
      <description>&lt;P&gt;Something like the below, note that it is not optimal coding, it is more to describe the thinking behind it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
  informat date date9.;
  input Shop_id Date;
datalines;
1 23MAR2015
1 01APR2015
2 01MAR2015
2 01MAY2015
;
run;

data have2;
  informat date date9.;
  input Shop_id Date Cust_id Gender;
datalines;
1 01MAR2015 113 1
1 01APR2015 115 0
2 03MAR2015 116 1
;
run;

proc sql;
  create table WANT as
  select  distinct  SHOP_ID
                    ,DATE
                    ,count(CUST_ID) as RESULT
  from  (select A.*
                ,B.CUST_ID
         from   HAVE1 A
         left join (select * from HAVE2 where GENDER=1) B
         on     A.SHOP_ID=B.SHOP_ID
         and    intnx('month',A.DATE,-1) &amp;lt;= B.DATE &amp;lt;= A.DATE)
  group by SHOP_ID,DATE;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Ok, so in the subquery, the from (), I join all female records back to the main dataset based on date being between date-1 month and date. &amp;nbsp;Then in the main query I count these using a by group.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Oct 2015 10:38:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Seeking-help-for-SAS-code/m-p/232400#M268114</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-10-30T10:38:52Z</dc:date>
    </item>
    <item>
      <title>Re: Seeking help for SAS code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Seeking-help-for-SAS-code/m-p/232431#M268115</link>
      <description>&lt;P&gt;First thing: make sure your dates as SAS date valued variables.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Oct 2015 14:25:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Seeking-help-for-SAS-code/m-p/232431#M268115</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-10-30T14:25:35Z</dc:date>
    </item>
  </channel>
</rss>

