<?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: coding help in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/coding-help/m-p/616755#M180617</link>
    <description>&lt;P&gt;If your real intent is to make the code more efficient, note that you can combine two steps into one.&amp;nbsp; You don't need to create TEST1 and then TEST2.&amp;nbsp; You could instead create your date variables and your flags in a single step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
	set test0;

	startdate = (intnx ('month', enterdate, -12, 'e'));
	endate = (intnx ('month' , enterdate, -0, 'e' ));
	extentiondate = (intnx ('month' , enterdate, -15, 'e' ));
	
format startdate enddate extentiondate mmddyy10.;

	if startdate le regdate le enddate then withinyr = 1;
		else if extentiondate le regdate le endate then withingrace = 1;
			else outsidetimeframe = 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can still run the PROC FREQ on the results of this step.&amp;nbsp; This will cut out nearly half the time it takes to run two DATA steps.&lt;/P&gt;</description>
    <pubDate>Sun, 12 Jan 2020 03:29:23 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2020-01-12T03:29:23Z</dc:date>
    <item>
      <title>coding help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/coding-help/m-p/616739#M180608</link>
      <description>&lt;P&gt;Hello everyone!. I'm new to posting and I am not a SAS expert so please bear with me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a code which I run monthly for a 13 month time period (i.e. if i run the code in October it will cover OCT 2018 to OCT 2019. The goal of the code is to determine how many birds were registered within a year of the enter date and how many birds were registered within the grace period which is a year plus 90 days of the enter date. After that is determined I calculate a compliant&lt;BR /&gt;percentage by adding the total birds registered within the year plus total birds registered within the grace period and divide by the total population for that month. The population totals come from a proc freq which is made in an earlier step which is not mention below.The mon_yr variable is also made in a previous step which is not listed below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output is created using proc report by simply displaying each variable. Any suggestions would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Beginning Data&lt;BR /&gt;ENTERDATE BIRDTYPES MON_YEAR ID REGDATE poptotal&lt;BR /&gt;7/31/2019 BLUEBIRD JUL_2019 100 11/2/2019 2&lt;BR /&gt;7/31/2019 BLUEBIRD JUL_2019 200 12/8/2018 2&lt;BR /&gt;8/31/2019 ROBIN AUG_2019 300 12/19/2017 2&lt;BR /&gt;8/31/2019 ROBIN AUG_2019 400 9/19/2019 2&lt;BR /&gt;9/31/2018 SPARROW SEP_2018 500 6/8/2019 2&lt;BR /&gt;9/31/2018 SPARROW SEP_2018 600 4/13/2019 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS Code&lt;/P&gt;&lt;P&gt;/*in order to be considered compliant the birds would need to be registered within 365 plus 90 days of the file date*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;/*in order to be considered compliant the birds would need to be registered within 365 plus &lt;BR /&gt;90 days of the enter date*/&lt;BR /&gt;&lt;BR /&gt;/*calculate relevant start and end dates*/&lt;BR /&gt;data test1;&lt;BR /&gt;	set test0;&lt;BR /&gt;&lt;BR /&gt;	startdate = (intnx ('month', enterdate, -12, 'e'));&lt;BR /&gt;	endate = (intnx ('month' , enterdate, -0, 'e' ));&lt;BR /&gt;	extentiondate = (intnx ('month' , enterdate, -15, 'e' ));&lt;BR /&gt;	&lt;BR /&gt;format startdate enddate extentiondate mmddyy10.;&lt;BR /&gt;	&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;/*check dates*/&lt;BR /&gt;proc freq data = test1; &lt;BR /&gt;	table birdtypes * startdate* enddate* extentiondate / list missing;&lt;BR /&gt;run; &lt;BR /&gt;&lt;BR /&gt;/*flag which time frame the birds registration is in */&lt;BR /&gt;data test2;&lt;BR /&gt;	set test1;&lt;BR /&gt;&lt;BR /&gt;	if startdate le regdate le enddate then withinyr = 1;&lt;BR /&gt;		else if extentiondate le regdate le endate then withingrace = 1;&lt;BR /&gt;			else outsidetimeframe = 1;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;/*calculate percentages*/&lt;BR /&gt;proc sql;&lt;BR /&gt;	create table test3 as&lt;BR /&gt;	select distinct birdtypes, mon_yr, sum(withinyr = 1) as reg_yr,&lt;BR /&gt;	sum(withingrace = 1) as regrace, sum(outsidetimeframe = 1) as noncompliant, &lt;BR /&gt;	calculated reg_yr + regrace = compliancetotal, &lt;BR /&gt;	calculated compliancetotal/poptotal = percent_compliant&lt;BR /&gt;from test2&lt;BR /&gt;group by birdtypes, mon_yr;&lt;BR /&gt;quit; &lt;/PRE&gt;</description>
      <pubDate>Sun, 12 Jan 2020 00:38:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/coding-help/m-p/616739#M180608</guid>
      <dc:creator>luvscandy27</dc:creator>
      <dc:date>2020-01-12T00:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: coding help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/coding-help/m-p/616743#M180610</link>
      <description>What exactly is your question here? is there some part that's not working? Are you looking to make it more efficient? Does your code not currently answer your question? Do you just want to make sure it's correct?</description>
      <pubDate>Sun, 12 Jan 2020 00:51:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/coding-help/m-p/616743#M180610</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-12T00:51:10Z</dc:date>
    </item>
    <item>
      <title>Re: coding help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/coding-help/m-p/616748#M180613</link>
      <description>The code works, I would like to make it more efficient.&lt;BR /&gt;&lt;BR /&gt;#- Please type your reply above this line. No attachments. -##</description>
      <pubDate>Sun, 12 Jan 2020 01:17:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/coding-help/m-p/616748#M180613</guid>
      <dc:creator>luvscandy27</dc:creator>
      <dc:date>2020-01-12T01:17:05Z</dc:date>
    </item>
    <item>
      <title>Re: coding help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/coding-help/m-p/616751#M180615</link>
      <description>&lt;P&gt;Questions then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;The goal of the code is to determine how many birds were registered within a year of the enter date and how many birds were registered within the grace period which is a year plus 90 days of the enter date. After that is determined I calculate a compliant&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;regDate = Registration Date&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;EnterDate = Date entered in system&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Your rule is one year - is that 365 days or a year? In a leap year, such as this, they may not be the same thing. Years and months are not standard&amp;nbsp;measures so 365 + 90 days is not the&amp;nbsp;same as one year plus 3 months so it's very&amp;nbsp;important that these terms are correct, especially if this is used in any actual business processes where someone will call you on it.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Why&amp;nbsp;are you aligning your dates to the end of the month? I don't see any logic in your question that would require that, so not&amp;nbsp;sure why you're doing that in the INTNX(). This could result in the wrong categorization, ie January 1 2019 is more than a year ago, but if you align both dates to the end of the month they become January 31 and it seems like it's within the period.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do think if you create your dummy variables, withinyr, withingrace, as 0/1 it may be easier to report. If you have binary variables and take the mean of them you get the percentage of success without needing any additional calculations so it could make your process easier.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you show what you would expect, EXACTLY, as output given what you've shown as input data?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may need to expand your input data to more accurately reflect your actual data in this step.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Here are instructions on how to provide sample data as a data step:&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Jan 2020 01:33:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/coding-help/m-p/616751#M180615</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-12T01:33:05Z</dc:date>
    </item>
    <item>
      <title>Re: coding help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/coding-help/m-p/616755#M180617</link>
      <description>&lt;P&gt;If your real intent is to make the code more efficient, note that you can combine two steps into one.&amp;nbsp; You don't need to create TEST1 and then TEST2.&amp;nbsp; You could instead create your date variables and your flags in a single step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
	set test0;

	startdate = (intnx ('month', enterdate, -12, 'e'));
	endate = (intnx ('month' , enterdate, -0, 'e' ));
	extentiondate = (intnx ('month' , enterdate, -15, 'e' ));
	
format startdate enddate extentiondate mmddyy10.;

	if startdate le regdate le enddate then withinyr = 1;
		else if extentiondate le regdate le endate then withingrace = 1;
			else outsidetimeframe = 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can still run the PROC FREQ on the results of this step.&amp;nbsp; This will cut out nearly half the time it takes to run two DATA steps.&lt;/P&gt;</description>
      <pubDate>Sun, 12 Jan 2020 03:29:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/coding-help/m-p/616755#M180617</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-01-12T03:29:23Z</dc:date>
    </item>
    <item>
      <title>Re: coding help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/coding-help/m-p/616757#M180619</link>
      <description>&lt;P&gt;It is 365 days plus 90 days.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The enter date is based on the time the data is complied. The data is compiled on the last day of every month. The regdate should not be aligned to the end of the month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to use binary variables and use your suggestion of "taking the mean of them you get the&lt;BR /&gt;percentage of success without needing any additional calculations so it could make your process easier. But maybe do this process&lt;BR /&gt;using the month variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I provided a sample below of what I think the output should look like M1-M13 represent months 1-13. I&lt;BR /&gt;am open to suggestions on how the output should look because I'm really would like to simplify my process and make my code more efficient.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BIRDTYPES ID M1 M2 M3 M4 M5 M6 M7 M8 M9 M10 M11 M12 M13&lt;BR /&gt;ROBIN 10 1 0 0 0 0 0 0 0 0 0 0 0 0 0&lt;BR /&gt;ROBIN 20 0 1 0 0 0 0 0 0 0 0 0 0 0 0&lt;BR /&gt;ROBIN 50 0 0 0 1 0 0 0 0 0 0 0 0 0 0&lt;BR /&gt;BLUEBIRD60 0 0 0 0 0 1 0 0 0 0 0 0 0 0&lt;BR /&gt;BLUEBIRD70 0 0 0 0 1 0 0 0 0 0 0 0 0 0&lt;BR /&gt;BLUEBIRD100 0 0 0 0 0 0 0 1 0 1 0 0 0 0&lt;BR /&gt;SPARROW 110 0 0 0 0 0 0 0 0 0 0 1 0 0 0&lt;BR /&gt;SPARROW 120 0 0 0 0 0 0 0 0 0 0 0 1 0 0&lt;/P&gt;</description>
      <pubDate>Sun, 12 Jan 2020 05:46:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/coding-help/m-p/616757#M180619</guid>
      <dc:creator>luvscandy27</dc:creator>
      <dc:date>2020-01-12T05:46:11Z</dc:date>
    </item>
  </channel>
</rss>

