<?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: How to establish successful rate? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-establish-successful-rate/m-p/788647#M252194</link>
    <description>&lt;P&gt;I don't know who else will help with this (you're asking for R help on a SAS forum), but the code you posted is chock full of errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One, it uses `length` when there is no variable named `length` (`project_lenght_days`).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Two, there isn't a value called "successful" -- it's "success".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Third, I'm not really sure how the rate is being calculated. The order, I believe, matters in the `group_by` statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Fourth, you usually get a warning when you subset a data set like that when using ggplot:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ggplot(length.pct[length.pct$state=="success",], aes(project_lenght_days, pct)))&lt;/PRE&gt;
&lt;P&gt;Fifth, the plot doesn't look anything like that. I would also typically categorize your variables in the mutate statement instead of relying on the plot options (probably worth it in the long run):&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="maguiremq_1-1641472360969.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67164i69A5C1C366B40053/image-size/medium?v=v2&amp;amp;px=400" role="button" title="maguiremq_1-1641472360969.png" alt="maguiremq_1-1641472360969.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sixth, you typically should call your libraries at the top of the script:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;library(tidyverse) 
library(ggthemes) # origin of `theme_economist`&lt;/PRE&gt;
&lt;P&gt;All this to say, I don't know if you provided enough information for us to replicate it in SAS.Here's the code I used to reproduce your example in R:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;library(tidyverse)&lt;BR /&gt;library(ggthemes)

ksdata  &amp;lt;- 
  tibble::tibble(
    state = c("success", "failed", "canceled", "success", "success", "failed", "failed", "canceled", "success", "failed"),
    project_lenght_days = c(9,5,6,15,17,12,22,23,25,27)
  )

length.pct &amp;lt;- ksdata %&amp;gt;%
  filter(state %in% c("success", "failed"), project_lenght_days &amp;lt;= 61) %&amp;gt;%
  group_by(project_lenght_days, state) %&amp;gt;%
  summarize(count=n()) %&amp;gt;%
  mutate(pct=count/sum(count))

length.pct

ggplot(length.pct[length.pct$state=="success",], aes(project_lenght_days, pct)) + 
  geom_point(colour="royalblue4", size=2.5) + ggtitle("Success Rate vs. Project Length") + 
  xlab("Project Length (Days)") + ylab("Success Rate (%)") + 
  scale_x_continuous(breaks=c(0,10,20,30,40,50,60)) + geom_vline(xintercept=30, colour="red") + 
  theme_economist() + 
  theme(plot.title=element_text(hjust=0.5), axis.title=element_text(size=12, face="bold"))
&lt;/PRE&gt;
&lt;P&gt;And here's an equivalent query in SAS using PROC SQL, but I don't have enough information to determine whether it's correct or not.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table 	length_pct as
		select
					state,
					project_lenght_days,
					count(*) as count_n,
					case 
						when 0 &amp;lt;= project_lenght_days &amp;lt; 10 then "0 - 10"
						when 10 &amp;lt;= project_lenght_days &amp;lt; 20 then "10 - 20"
						else "20 - 30"
					end as interval
		from
					have
		where
					state in ("success", "failed") and project_lenght_days &amp;lt;= 61
		group by
					state, project_lenght_days;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'm not going to plot it, but you can look into PROC SGPLOT if we figure out all the issues.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/p1t32i8511t1gfn17sw07yxtazad.htm" target="_blank" rel="noopener"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/p1t32i8511t1gfn17sw07yxtazad.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Apologies if I'm missing something that you explained or if I made typo --&amp;nbsp; I was just trying to be clear in my explanation and attempting to reproduce across languages can be a bit difficult.&lt;/P&gt;</description>
    <pubDate>Thu, 06 Jan 2022 12:40:36 GMT</pubDate>
    <dc:creator>maguiremq</dc:creator>
    <dc:date>2022-01-06T12:40:36Z</dc:date>
    <item>
      <title>How to establish successful rate?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-establish-successful-rate/m-p/788625#M252184</link>
      <description>&lt;P&gt;Let's assume I have data like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;
input state $ project_lenght_days;
cards;
success 9
failed 5
canceled 6
success 15
success 17
failed 12
failed 22
canceled 23
success 25
failed 27
;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to establish successful rate and present it as interval on chart 1-10, 10-20, 20-30 days.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've found the same analyze on kaggle, but it's in R, code from the analyze is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=""&gt;&lt;CODE class=""&gt;length.pct &amp;lt;- ksdata %&amp;gt;%
  filter(state %&lt;SPAN class=""&gt;in&lt;/SPAN&gt;% c(&lt;SPAN class=""&gt;"successful"&lt;/SPAN&gt;, &lt;SPAN class=""&gt;"failed"&lt;/SPAN&gt;), length &amp;lt;= &lt;SPAN class=""&gt;61&lt;/SPAN&gt;) %&amp;gt;%
  group_by(length, state) %&amp;gt;%
  summarize(count=n()) %&amp;gt;%
  mutate(pct=count/sum(count))

ggplot(length.pct[length.pct$state==&lt;SPAN class=""&gt;"successful"&lt;/SPAN&gt;,], aes(length, pct)) + 
  geom_point(colour=&lt;SPAN class=""&gt;"royalblue4"&lt;/SPAN&gt;, size=&lt;SPAN class=""&gt;2.5&lt;/SPAN&gt;) + ggtitle(&lt;SPAN class=""&gt;"Success Rate vs. Project Length"&lt;/SPAN&gt;) + 
  xlab(&lt;SPAN class=""&gt;"Project Length (Days)"&lt;/SPAN&gt;) + ylab(&lt;SPAN class=""&gt;"Success Rate (%)"&lt;/SPAN&gt;) + 
  scale_x_continuous(breaks=c(&lt;SPAN class=""&gt;0&lt;/SPAN&gt;,&lt;SPAN class=""&gt;10&lt;/SPAN&gt;,&lt;SPAN class=""&gt;20&lt;/SPAN&gt;,&lt;SPAN class=""&gt;30&lt;/SPAN&gt;,&lt;SPAN class=""&gt;40&lt;/SPAN&gt;,&lt;SPAN class=""&gt;50&lt;/SPAN&gt;,&lt;SPAN class=""&gt;60&lt;/SPAN&gt;)) + geom_vline(xintercept=&lt;SPAN class=""&gt;30&lt;/SPAN&gt;, colour=&lt;SPAN class=""&gt;"red"&lt;/SPAN&gt;) + 
  theme_economist() + 
  theme(plot.title=element_text(hjust=&lt;SPAN class=""&gt;0.5&lt;/SPAN&gt;), axis.title=element_text(size=&lt;SPAN class=""&gt;12&lt;/SPAN&gt;, face=&lt;SPAN class=""&gt;"bold"&lt;/SPAN&gt;))&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In my data I assume that canceled and failed state are equal to failed project.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to make something like this in SAS with the sample Data i have?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="przyklad.png" style="width: 610px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67160i2AE4F806B883C9DE/image-dimensions/610x305?v=v2" width="610" height="305" role="button" title="przyklad.png" alt="przyklad.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Thu, 06 Jan 2022 11:26:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-establish-successful-rate/m-p/788625#M252184</guid>
      <dc:creator>moteku</dc:creator>
      <dc:date>2022-01-06T11:26:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to establish successful rate?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-establish-successful-rate/m-p/788647#M252194</link>
      <description>&lt;P&gt;I don't know who else will help with this (you're asking for R help on a SAS forum), but the code you posted is chock full of errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One, it uses `length` when there is no variable named `length` (`project_lenght_days`).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Two, there isn't a value called "successful" -- it's "success".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Third, I'm not really sure how the rate is being calculated. The order, I believe, matters in the `group_by` statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Fourth, you usually get a warning when you subset a data set like that when using ggplot:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ggplot(length.pct[length.pct$state=="success",], aes(project_lenght_days, pct)))&lt;/PRE&gt;
&lt;P&gt;Fifth, the plot doesn't look anything like that. I would also typically categorize your variables in the mutate statement instead of relying on the plot options (probably worth it in the long run):&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="maguiremq_1-1641472360969.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67164i69A5C1C366B40053/image-size/medium?v=v2&amp;amp;px=400" role="button" title="maguiremq_1-1641472360969.png" alt="maguiremq_1-1641472360969.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sixth, you typically should call your libraries at the top of the script:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;library(tidyverse) 
library(ggthemes) # origin of `theme_economist`&lt;/PRE&gt;
&lt;P&gt;All this to say, I don't know if you provided enough information for us to replicate it in SAS.Here's the code I used to reproduce your example in R:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;library(tidyverse)&lt;BR /&gt;library(ggthemes)

ksdata  &amp;lt;- 
  tibble::tibble(
    state = c("success", "failed", "canceled", "success", "success", "failed", "failed", "canceled", "success", "failed"),
    project_lenght_days = c(9,5,6,15,17,12,22,23,25,27)
  )

length.pct &amp;lt;- ksdata %&amp;gt;%
  filter(state %in% c("success", "failed"), project_lenght_days &amp;lt;= 61) %&amp;gt;%
  group_by(project_lenght_days, state) %&amp;gt;%
  summarize(count=n()) %&amp;gt;%
  mutate(pct=count/sum(count))

length.pct

ggplot(length.pct[length.pct$state=="success",], aes(project_lenght_days, pct)) + 
  geom_point(colour="royalblue4", size=2.5) + ggtitle("Success Rate vs. Project Length") + 
  xlab("Project Length (Days)") + ylab("Success Rate (%)") + 
  scale_x_continuous(breaks=c(0,10,20,30,40,50,60)) + geom_vline(xintercept=30, colour="red") + 
  theme_economist() + 
  theme(plot.title=element_text(hjust=0.5), axis.title=element_text(size=12, face="bold"))
&lt;/PRE&gt;
&lt;P&gt;And here's an equivalent query in SAS using PROC SQL, but I don't have enough information to determine whether it's correct or not.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table 	length_pct as
		select
					state,
					project_lenght_days,
					count(*) as count_n,
					case 
						when 0 &amp;lt;= project_lenght_days &amp;lt; 10 then "0 - 10"
						when 10 &amp;lt;= project_lenght_days &amp;lt; 20 then "10 - 20"
						else "20 - 30"
					end as interval
		from
					have
		where
					state in ("success", "failed") and project_lenght_days &amp;lt;= 61
		group by
					state, project_lenght_days;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'm not going to plot it, but you can look into PROC SGPLOT if we figure out all the issues.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/p1t32i8511t1gfn17sw07yxtazad.htm" target="_blank" rel="noopener"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/p1t32i8511t1gfn17sw07yxtazad.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Apologies if I'm missing something that you explained or if I made typo --&amp;nbsp; I was just trying to be clear in my explanation and attempting to reproduce across languages can be a bit difficult.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jan 2022 12:40:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-establish-successful-rate/m-p/788647#M252194</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2022-01-06T12:40:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to establish successful rate?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-establish-successful-rate/m-p/788689#M252220</link>
      <description>&lt;P&gt;Hi, I wanted to create something what is in R, but converted to SAS. Maybe I didnt specify my quetion. Between 1-10 days theres is 1 success and 2 failed (failed + canceled = 2 failed) so the success rate between 1-10 days equals 1/3. Between 10-20 we have 2/3, between 20-30days we have 1/4. Dont know how to loop it properly to get results 1/3 or 2/3 or 1/4.&lt;/P&gt;&lt;P&gt;The whole data i have has more than 5000 rows which have project_length_days between 1 and 60.&amp;nbsp;&lt;BR /&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jan 2022 17:07:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-establish-successful-rate/m-p/788689#M252220</guid>
      <dc:creator>moteku</dc:creator>
      <dc:date>2022-01-06T17:07:44Z</dc:date>
    </item>
  </channel>
</rss>

