<?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: Simulation in data step or proc sql in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432357#M22747</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&lt;/P&gt;&lt;P&gt;I have programmed below so far. I'm baffled here. I wanted to summarize the data by agecat and the risk intervals so that I can plot risk vs bias stratified by agecat. I'd appreciate any comments.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="bias_risk plot.png" style="width: 254px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18203i5336ADD90C5F5947/image-size/large?v=v2&amp;amp;px=999" role="button" title="bias_risk plot.png" alt="bias_risk plot.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data risk; 
input risk;
datalines;
0
0.05
0.1
0.15
0.2
0.25
0.3
0.35
0.4
0.45
0.5
0.55
0.6
0.65
0.7
0.75
0.8
0.85
0.9
0.95
1
;
data risk; set risk ;
obs_num=_n_;
run;

proc sql; 
 create table cartes_join as 
 select
 a.obs_num as obs_num_1, b.obs_num as obs_num_2,
 a.risk as risk_out, b.risk as risk_in
 from
 risk as a INNER JOIN risk as b  
 on
a.obs_num &amp;gt;b.obs_num; 
quit;

proc sql;
create table final_risk as
select *
from cartes_join cross join support;
quit;

data final_risk; set final_risk;
cases_among_inflow=risk_in*sum_inflow;
cases_among_outflow=risk_out*sum_outflow;
pop_adj_mobility=tot_pop+cases_among_inflow-cases_among_outflow-tot_case;
rate_adj=tot_case/pop_adj_mobility;
rate_crude=tot_case/(tot_pop-tot_case);
bias=((rate_adj-rate_crude)/rate_crude)*100;
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 30 Jan 2018 18:20:53 GMT</pubDate>
    <dc:creator>Cruise</dc:creator>
    <dc:date>2018-01-30T18:20:53Z</dc:date>
    <item>
      <title>Simulation in data step or proc sql</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432229#M22737</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to calculate all possible number of disease cases across the probability of risk developing a disease from 0 through 1 by interval of 0.01 among inflow and outflow groups?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. n_inflow=number of inflow *risk (p [0,1 by 0.01])?&lt;/P&gt;&lt;P&gt;1. n_outflow=number of outflow *risk (p [0,1 by 0.01])?&lt;/P&gt;&lt;P&gt;2. take cartesian product of diff(n_inflow - n_outflow) to compute the difference&lt;/P&gt;&lt;P&gt;3. total population + diff&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll highly appreciate your suggestions or example/demo codes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In attached data:&lt;/P&gt;&lt;P&gt;tot_case=number of high-risk individual&lt;/P&gt;&lt;P&gt;tot_pop= total population&lt;/P&gt;&lt;P&gt;sum_inflow=n_inflow&lt;/P&gt;&lt;P&gt;sum_outflow=n_outflow&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;using SAS 9.4.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 16:20:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432229#M22737</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-01-30T16:20:36Z</dc:date>
    </item>
    <item>
      <title>Re: Simulation in data step or proc sql</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432265#M22739</link>
      <description>&lt;P&gt;If you have a SAS data set use this: Instructions here: &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; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If we have to read your csv it is not unlikely that we make choices such that variables are different types than yours and code possibly would not be compatible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And show what you have tried.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 15:45:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432265#M22739</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-01-30T15:45:59Z</dc:date>
    </item>
    <item>
      <title>Re: Simulation in data step or proc sql</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432272#M22740</link>
      <description>Original form of data was csv. And I imported to SAS using proc import. Attached csv file is the original data that I simply kept first N=131 observations. Do you still want me to follow the instruction? Just let me know please. Thanks for help in advance.</description>
      <pubDate>Tue, 30 Jan 2018 15:52:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432272#M22740</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-01-30T15:52:06Z</dc:date>
    </item>
    <item>
      <title>Re: Simulation in data step or proc sql</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432282#M22741</link>
      <description>&lt;P&gt;It's not that simple. Your outflow/inflow can be larger than your new_cases and you need to account for that as well.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 15:58:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432282#M22741</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-30T15:58:42Z</dc:date>
    </item>
    <item>
      <title>Re: Simulation in data step or proc sql</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432289#M22742</link>
      <description>Hi Reeza, I'd compute the probability of all new cases to move in and move out independent from the extent of outflow and total inflow, at the moment. Let me start with the simple mutually exclusive probability.</description>
      <pubDate>Tue, 30 Jan 2018 16:04:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432289#M22742</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-01-30T16:04:19Z</dc:date>
    </item>
    <item>
      <title>Re: Simulation in data step or proc sql</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432291#M22743</link>
      <description>&lt;P&gt;Maybe I'm misunderstanding, because I assume you didn't have the probability which is why you were simulating what happens when the probability goes from 0 to 1 in each case.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 16:06:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432291#M22743</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-30T16:06:12Z</dc:date>
    </item>
    <item>
      <title>Re: Simulation in data step or proc sql</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432311#M22744</link>
      <description>Reeza, you're right. Good catch! I appreciate it. I just edited my post to how it's supposed to be worded.</description>
      <pubDate>Tue, 30 Jan 2018 16:19:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432311#M22744</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-01-30T16:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: Simulation in data step or proc sql</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432314#M22745</link>
      <description>&lt;P&gt;This is my primordial effort to program. At least how I visualize the problem. I will link data cartes_join to my original case data. I used interval 0.01 to make it categorical because I don't know how to run continuous simulation yet.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data risk; 
input risk;
datalines;
0
0.05
0.1
0.15
0.2
0.25
0.3
0.35
0.4
0.45
0.5
0.55
0.6
0.65
0.7
0.75
0.8
0.85
0.9
0.95
1
;
data risk; set risk ;
obs_num=_n_;
run;

proc sql; 
 create table cartes_join as 
 select
 a.obs_num as obs_num_1, b.obs_num as obs_num_2,
 a.risk as risk_out, b.risk as risk_in
 from
 risk as a INNER JOIN risk as b  
 on
a.obs_num &amp;gt;b.obs_num; 
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 16:26:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432314#M22745</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-01-30T16:26:17Z</dc:date>
    </item>
    <item>
      <title>Re: Simulation in data step or proc sql</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432325#M22746</link>
      <description>&lt;P&gt;Now take that data set and take a single line of your data and create the numbers you need - so use the Max/MIN functions to determine your N and each of the calculations you need.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you have it running for a single iteration, I can help you make it into a macro but unfortunately I don't have time to spend on this - it's a more complex issue but totally doable and I'm trying to work through my own complex recoding at the moment &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 16:35:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432325#M22746</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-30T16:35:37Z</dc:date>
    </item>
    <item>
      <title>Re: Simulation in data step or proc sql</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432357#M22747</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&lt;/P&gt;&lt;P&gt;I have programmed below so far. I'm baffled here. I wanted to summarize the data by agecat and the risk intervals so that I can plot risk vs bias stratified by agecat. I'd appreciate any comments.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="bias_risk plot.png" style="width: 254px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18203i5336ADD90C5F5947/image-size/large?v=v2&amp;amp;px=999" role="button" title="bias_risk plot.png" alt="bias_risk plot.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data risk; 
input risk;
datalines;
0
0.05
0.1
0.15
0.2
0.25
0.3
0.35
0.4
0.45
0.5
0.55
0.6
0.65
0.7
0.75
0.8
0.85
0.9
0.95
1
;
data risk; set risk ;
obs_num=_n_;
run;

proc sql; 
 create table cartes_join as 
 select
 a.obs_num as obs_num_1, b.obs_num as obs_num_2,
 a.risk as risk_out, b.risk as risk_in
 from
 risk as a INNER JOIN risk as b  
 on
a.obs_num &amp;gt;b.obs_num; 
quit;

proc sql;
create table final_risk as
select *
from cartes_join cross join support;
quit;

data final_risk; set final_risk;
cases_among_inflow=risk_in*sum_inflow;
cases_among_outflow=risk_out*sum_outflow;
pop_adj_mobility=tot_pop+cases_among_inflow-cases_among_outflow-tot_case;
rate_adj=tot_case/pop_adj_mobility;
rate_crude=tot_case/(tot_pop-tot_case);
bias=((rate_adj-rate_crude)/rate_crude)*100;
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Jan 2018 18:20:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432357#M22747</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-01-30T18:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: Simulation in data step or proc sql</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432369#M22749</link>
      <description>I can't run your code so &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;I'm not sure how that calculation would work overall tbh and if you can't define it, then I'm definitely not sure how it would work.</description>
      <pubDate>Tue, 30 Jan 2018 17:46:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432369#M22749</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-30T17:46:08Z</dc:date>
    </item>
    <item>
      <title>Re: Simulation in data step or proc sql</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432384#M22751</link>
      <description>Reeza, did you indicate here that you're trying more complex code to solve the problem I posted here? I'd love to see your approach so.</description>
      <pubDate>Tue, 30 Jan 2018 18:05:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432384#M22751</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-01-30T18:05:49Z</dc:date>
    </item>
    <item>
      <title>Re: Simulation in data step or proc sql</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432389#M22752</link>
      <description>&lt;P&gt;No, I tried to run your code and it didn't run.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;But I don't see where you linked it back to your pop data and did the calculations for the possible N that you were looking for&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 18:13:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432389#M22752</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-30T18:13:47Z</dc:date>
    </item>
    <item>
      <title>Re: Simulation in data step or proc sql</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432405#M22753</link>
      <description>my pop data is named support in the second proc sql where I'm linking risk Cartesian file back to pop data =support. Hope you can run now. Possible Ns are cases_among_inflow and cases_among_outflow as shown in the data step. Please let me know your comments.</description>
      <pubDate>Tue, 30 Jan 2018 18:23:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432405#M22753</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-01-30T18:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: Simulation in data step or proc sql</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432469#M22767</link>
      <description>&lt;P&gt;I got here, not sure about how the next set of calcs need to happen, but from here you can calculate the numbers you need and then aggregate them to what you need.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you post that back once you have it figured out I can help you generalize it a bit more.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because this is still in development stages I only used a single row from the support data to simplify this and for others to work off, if desired.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data support;
	input county agecat tot_pop tot_case sum_inflow sum_outflow;
	cards;
1 12 17881 235 373 217
;
run;

data risk;
	do risk=0 to 1 by 0.05;
		output;
	end;
run;

proc sql;
	create table risk_cross as
		select t1.risk as risk_in, t2.risk as risk_out, t3.*
			from risk as t1
				cross join risk as t2
				cross join support as t3;
quit;

data calcs;
	set risk_cross;
	cases_in = min(risk_in*sum_inflow, tot_case);
	cases_out = min(risk_out*sum_outflow, tot_case);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 19:47:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Simulation-in-data-step-or-proc-sql/m-p/432469#M22767</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-30T19:47:24Z</dc:date>
    </item>
  </channel>
</rss>

