gretaolsson Tracker
https://communities.sas.com/kntur85557/tracker
gretaolsson TrackerSat, 14 Sep 2024 12:14:53 GMT2024-09-14T12:14:53ZExact logistic regression continous variable
https://communities.sas.com/t5/Statistical-Procedures/Exact-logistic-regression-continous-variable/m-p/357378#M18763
<P>Hi,</P><P><BR />I want to execute Exact logistic regression on a sample with a continuous variable. The sample size is 100 and below I show an extract from the data:</P><P> </P><P> </P><PRE>"","num","y","x"
"1",1,1,0.242106882663965
"2",1,0,-1.0215795935404
"3",1,1,-0.166510155016807
"4",1,0,-0.979868182931502
"5",1,1,0.078228780249738
"6",1,0,-0.37946718709135
"7",1,1,2.22519466020747
"8",1,0,0.0303031993682403
"9",1,0,-1.82711480734735
"10",1,0,1.1355902983012</PRE><P><SPAN>I use the following code: </SPAN></P><P> </P><P> </P><PRE>proc import out = filename
file = "/folders/myfolders/sasuser.v94/Btest.csv"
dbms = CSV
replace;
run;
data want;
set filename;
sampleid=ceil(_n_/100); /* Assign sampleid as record blocks of 10 */
run;
proc logistic data=want desc;
by sampleid;
model y = x;
exact x / estimate = both;
run;</PRE><P> </P><P><SPAN>(The beginning of the code I have because later on I want to have a csv file with several samples to be analyzed.)</SPAN></P><P> </P><P><SPAN>And I get the following message:</SPAN></P><P><SPAN>An exception was thrown while sending a packet to the peer. <BR />What am I doing wrong?</SPAN></P>Wed, 10 May 2017 05:17:17 GMThttps://communities.sas.com/t5/Statistical-Procedures/Exact-logistic-regression-continous-variable/m-p/357378#M18763gretaolsson2017-05-10T05:17:17ZRe: Do loop
https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/356269#M83527
<P><SPAN>I would like to save all the parameter estimates from each sample to a vector or list, is that possible?</SPAN></P>Fri, 05 May 2017 08:34:52 GMThttps://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/356269#M83527gretaolsson2017-05-05T08:34:52ZRe: Do loop
https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/356268#M83526
<P><SPAN>What do you mean with <dataset to store>? <BR />Should I create a new file where I can save, for example, estimates? How do I do that then?</SPAN></P>Fri, 05 May 2017 08:30:36 GMThttps://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/356268#M83526gretaolsson2017-05-05T08:30:36ZRe: Do loop
https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/356133#M83475
<P>Hi!</P><P>I changed the code and now it works! T<SPAN>hank you very much!</SPAN></P><P> </P><PRE>PROC IMPORT OUT = filename
FILE = "/folders/myshortcuts/sf_myfolder/filename.csv"
DBMS = CSV
REPLACE;
RUN;
data want;
set filename;
sampleid=ceil(_n_/10); /* Assign sampleid as record blocks of 10 */
run;
proc logistic data=want;
by sampleid;
class x y;
model y = x;
run;</PRE><P><BR />Is it possible to extract specific values (estimates and p-values) from the result of each regression and put them together into a vector or something similar?</P><P> </P>Thu, 04 May 2017 21:00:51 GMThttps://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/356133#M83475gretaolsson2017-05-04T21:00:51ZRe: Do loop
https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/356105#M83461
<P> </P><P>Hi,</P><P>This was really helpful, thankyou!</P><P> </P><P>I have some questions, I think Im missing something obvious. <BR />Now I have the following code: </P><P> </P><P> </P><PRE>PROC IMPORT OUT = filename
FILE = "/folders/myshortcuts/sf_myfolder/filename.csv"
DBMS = CSV
REPLACE;
RUN;<BR />
data want;
set have;
sampleid=ceil(_n_/10); /* Assign sampleid as record blocks of 10 */
run;<BR />
proc logistic data=want;
by sampleid;
class x y;
model y = x;
run;</PRE><P>Of course, this does not work and my log looks like this:</P><P> </P><P>...</P><P> </P><DIV class="sasNote">NOTE: WORK.FILENAME data set was successfully created.</DIV><DIV class="sasNote">NOTE: The data set WORK.FILENAME has 100 observations and 4 variables.</DIV><DIV class="sasNote">NOTE: PROCEDURE IMPORT used (Total process time):</DIV><DIV class="sasNote">real time 0.06 seconds</DIV><DIV class="sasNote">cpu time 0.04 seconds</DIV><DIV class="sasNote"> </DIV><DIV class="sasNote"> </DIV><DIV class="sasSource">95</DIV><DIV class="sasSource">96 data want;</DIV><DIV class="sasSource">97 set have;</DIV><DIV class="sasError"><FONT color="#FF0000">ERROR: File WORK.HAVE.DATA does not exist.</FONT></DIV><DIV class="sasSource">98 sampleid=ceil(_n_/10); /* Assign sampleid as record blocks of 10 */</DIV><DIV class="sasSource">99 run;</DIV><DIV class="sasNote"> </DIV><DIV class="sasNote">NOTE: The SAS System stopped processing this step because of errors.</DIV><DIV class="sasWarning">WARNING: The data set WORK.WANT may be incomplete. When this step was stopped there were 0 observations and 1 variables.</DIV><DIV class="sasNote">NOTE: DATA statement used (Total process time):</DIV><DIV class="sasNote">real time 0.00 seconds</DIV><DIV class="sasNote">cpu time 0.01 seconds</DIV><DIV class="sasNote"> </DIV><DIV class="sasNote"> </DIV><DIV class="sasSource">100</DIV><DIV class="sasNote">NOTE: PROCEDURE LOGISTIC used (Total process time):</DIV><DIV class="sasNote">real time 0.00 seconds</DIV><DIV class="sasNote">cpu time 0.00 seconds</DIV><DIV class="sasNote"> </DIV><DIV class="sasError"><FONT color="#FF0000">ERROR: Variable X not found.</FONT></DIV><DIV class="sasError"><FONT color="#FF0000">ERROR: Variable Y not found.</FONT></DIV><DIV class="sasNote">NOTE: The SAS System stopped processing this step because of errors.</DIV><DIV class="sasSource">101 proc logistic data=want;</DIV><DIV class="sasSource">102 by sampleid;</DIV><DIV class="sasSource">103 class x y;</DIV><DIV class="sasSource">104 model y = x;</DIV><DIV class="sasSource">105 run;</DIV><DIV class="sasSource">106</DIV><DIV class="sasSource">107 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;</DIV><DIV class="sasSource">120</DIV><DIV class="sasSource"> </DIV><DIV class="sasSource"><BR /><STRONG>I thought I would replace "want" with "filename", but it did not work. How should I do?</STRONG></DIV>Thu, 04 May 2017 20:13:38 GMThttps://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/356105#M83461gretaolsson2017-05-04T20:13:38ZRe: Do loop
https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/355936#M83401
<P>Okay, I did not really catch any question, sorry.</P><P> </P><P>I have a CSV file containing 100 samples.<BR />Each sample consists of 10 observations. (So overall I have 1000 observations in one file.)</P><P> </P><P>I now want to let SAS read the CSV file and perform logistic regression on the first sample, which is observation "1" to "10" in the CSV-file, then I want SAS to perform logistic regression on the second sample, <SPAN>w</SPAN><SPAN>hich is observation "11" to "20" in the CSV-file, </SPAN>and so on and on.<BR />Above I have sent an excerpt on how the data looks in the CSV file. "1" - "10" is the first sample,<BR />"11" - "20" is the second sample, ...., "91" - "100" is the tenth sample and so on up to the hundred sample.</P><P> </P><P>If you have any more questions that you need answered, please let me know.</P>Thu, 04 May 2017 12:18:16 GMThttps://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/355936#M83401gretaolsson2017-05-04T12:18:16ZRe: Do loop
https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/355931#M83398
<P><SPAN>How does SAS know how many observations it is in each sample? </SPAN></P><P><SPAN>This did not work for me ....</SPAN></P>Thu, 04 May 2017 11:53:51 GMThttps://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/355931#M83398gretaolsson2017-05-04T11:53:51ZDo loop
https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/355547#M83268
<P><SPAN>Hello, </SPAN></P><P> </P><P><SPAN>I have a CSV file containing 100 samples a 10 observations each. How do I perform logistic regression on each individual sample from the one csv-file? How do I extract the values I'm interested in to a vector, such as estimatates and p-values? </SPAN></P><P> </P><P><SPAN>proc logistic data = WORK.IMPORT;<BR />class x y;<BR />model y = x;<BR />run;</SPAN></P><P> </P><P><SPAN>Here is an extract from the CSV-file:</SPAN></P><P> </P><P><SPAN>"","num","y","x"<BR />"1",1,1,0<BR />"2",1,1,1<BR />"3",1,1,1<BR />"4",1,1,1<BR />"5",1,1,0<BR />"6",1,1,0<BR />"7",1,1,1<BR />"8",1,1,1<BR />"9",1,1,1<BR />"10",1,1,1<BR />"11",1,1,1<BR />"12",1,1,1<BR />"13",1,1,0<BR />"14",1,0,0<BR />"15",1,1,0<BR />"16",1,1,0<BR />"17",1,1,0<BR />"18",1,1,1<BR />"19",1,1,1<BR />"20",1,1,0<BR />"21",1,0,0<BR />"22",1,1,1<BR />"23",1,0,0<BR />"24",1,1,1<BR />"25",1,1,1<BR />"26",1,1,1<BR />"27",1,1,0<BR />"28",1,1,1<BR />"29",1,0,0<BR />"30",1,1,0<BR />"31",1,1,1<BR />"32",1,1,0<BR />"33",1,1,1<BR />"34",1,1,0<BR />"35",1,0,0<BR />"36",1,1,0<BR />"37",1,1,0<BR />"38",1,0,1<BR />"39",1,1,1<BR />"40",1,1,1<BR />"41",1,1,0</SPAN></P><P> </P><P> </P><P><SPAN>Grateful for all the help I can get!</SPAN></P>Wed, 03 May 2017 12:10:13 GMThttps://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/355547#M83268gretaolsson2017-05-03T12:10:13ZTransfer data and loops
https://communities.sas.com/t5/SAS-Programming/Transfer-data-and-loops/m-p/349699#M81170
<PRE class="tw-data-text tw-ta tw-text-small"><SPAN>Hello,
I want to analyze simulated data of different sizes in both R and SAS. <BR />I have simulated all the samples in R and where I've done all my analysis, now I want to analyze <BR />all of those samples in SAS. All samples are in a the data frame.<BR />I want to do logistic regression and exact logistic regression, <BR />and I'm interested in the estimated coefficients. (university edition)
1. How do I transfer all samples to SAS smoothly? (So that point 2 gets easy)
2. How do I make a loop so that I can analyze all the data directly? <BR />Note that the sample size goes from 5-1500 with an increment of 5 and for now I <BR />only have one explanatory variable.<BR /><BR />Plz help :)</SPAN></PRE>Thu, 13 Apr 2017 09:43:03 GMThttps://communities.sas.com/t5/SAS-Programming/Transfer-data-and-loops/m-p/349699#M81170gretaolsson2017-04-13T09:43:03ZRe: Exact logistic regression
https://communities.sas.com/t5/Statistical-Procedures/Exact-logistic-regression/m-p/349362#M18319
<P>My Data:<BR />y x1 x2<BR />1. 1 1.489611900786800 -0.486983894512530<BR />2. 1 0.887638190472230 -0.899961461187430<BR />3. 1 -0.328400349680380 0.320480850960210<BR />4. 0 -1.283346136073470 0.314729922388780<BR />5. 1 -0.014384666024895 -1.040793737862780<BR />6. 1 1.005337941612940 0.385444205622100<BR />7. 1 0.403112850999760 0.797554772638080<BR />8. 1 1.432508077938930 -0.553701810045310<BR />9. 1 0.137341139238340 0.177313212434980<BR />10. 0 -1.341507064615280 0.042985039337917</P><P>Logg:<BR />1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;<BR />61<BR />62 PROC IMPORT DATAFILE=REFFILE<BR />63 DBMS=DBF<BR />64 OUT=WORK.IMPORT1;<BR />65 RUN;<BR /><BR />NOTE: Import cancelled. Output dataset WORK.IMPORT1 already exists. Specify REPLACE option to overwrite it.<BR />NOTE: The SAS System stopped processing this step because of errors.<BR />NOTE: PROCEDURE IMPORT used (Total process time):<BR />real time 0.00 seconds<BR />cpu time 0.00 seconds<BR /><BR />66<BR />67<BR /><BR /><BR />68 proc logistic data = WORK.IMPORT1;<BR />69 model y = x1 x2;<BR />70 run;<BR /><BR />NOTE: PROC LOGISTIC is modeling the probability that y=0. One way to change this to model the probability that y=1 is to specify<BR />the response variable option EVENT='1'.<BR />WARNING: There is a complete separation of data points. The maximum likelihood estimate does not exist.<BR />WARNING: The LOGISTIC procedure continues in spite of the above warning. Results shown are based on the last maximum likelihood<BR />iteration. Validity of the model fit is questionable.<BR />NOTE: There were 10 observations read from the data set WORK.IMPORT1.<BR />NOTE: PROCEDURE LOGISTIC used (Total process time):<BR />real time 0.12 seconds<BR />cpu time 0.12 seconds<BR /><BR /><BR />71<BR />72 proc logistic data = WORK.IMPORT1 desc;<BR />73 model y = x1 x2;<BR />74 exact x1 x2 /estimate=both;<BR />75 run;<BR /><BR />NOTE: PROC LOGISTIC is modeling the probability that y=1.<BR />WARNING: There is a complete separation of data points. The maximum likelihood estimate does not exist.<BR />WARNING: The LOGISTIC procedure continues in spite of the above warning. Results shown are based on the last maximum likelihood<BR />iteration. Validity of the model fit is questionable.<BR />NOTE: There were 10 observations read from the data set WORK.IMPORT1.<BR />NOTE: PROCEDURE LOGISTIC used (Total process time):<BR />real time 0.12 seconds<BR />cpu time 0.12 seconds<BR /><BR /><BR />76<BR />77 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;<BR />90</P>Wed, 12 Apr 2017 10:15:52 GMThttps://communities.sas.com/t5/Statistical-Procedures/Exact-logistic-regression/m-p/349362#M18319gretaolsson2017-04-12T10:15:52ZRe: Exact logistic regression
https://communities.sas.com/t5/Statistical-Procedures/Exact-logistic-regression/m-p/349319#M18316
Do I need to give more information to get any help?Wed, 12 Apr 2017 05:17:10 GMThttps://communities.sas.com/t5/Statistical-Procedures/Exact-logistic-regression/m-p/349319#M18316gretaolsson2017-04-12T05:17:10ZExact logistic regression
https://communities.sas.com/t5/Statistical-Procedures/Exact-logistic-regression/m-p/349161#M18311
<PRE class="tw-data-text tw-ta tw-text-small"><SPAN>Hi, <BR />I want to perform <STRONG>exact</STRONG> logistic regression in SAS. I've found the following code that I want to apply to different samples of varying size.
(I use the university edition. )<BR /><BR />PROC IMPORT DATAFILE=REFFILE<BR /> DBMS=DBF<BR /> OUT=WORK.IMPORT;<BR />RUN;<BR /><BR />proc logistic data = WORK.IMPORT desc;<BR /> model y = x1 x2;<BR /> exact x1 x2 / estimate = both;<BR />run;<BR /><BR /><BR />When I run this code I get empty tables with no estimates...
Must the data be written in a specific way, in that case, how?
I can perform ordinary logistic regression on the samples, and my goal is to compare the results.<BR /><BR />I have attached the three files, log, results and data - that contains 20 observations. Because the files did not have the valid extension they are all in paint, sorry for that.<BR /><BR />I'm grateful for all the help I can get.<BR /></SPAN></PRE><P> </P><BR /><IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13696i4B45A68578A9A007/image-size/large?v=1.0&px=600" border="0" alt="data.png" title="data.png" /><IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13697iC005F8B607BA09A1/image-size/large?v=1.0&px=600" border="0" alt="Empty_Results_ Test_log_regr.png" title="Empty_Results_ Test_log_regr.png" /><IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13698i671954EA5810802C/image-size/large?v=1.0&px=600" border="0" alt="Logg.png" title="Logg.png" />Tue, 11 Apr 2017 15:18:59 GMThttps://communities.sas.com/t5/Statistical-Procedures/Exact-logistic-regression/m-p/349161#M18311gretaolsson2017-04-11T15:18:59ZHow do I solve Error: Statement is not valid or it is used out of proper order. (and make loops in)
https://communities.sas.com/t5/SAS-Programming/How-do-I-solve-Error-Statement-is-not-valid-or-it-is-used-out-of/m-p/348168#M80591
<P><SPAN>I am completely new to SAS. You can see my code below. When I run the last part, I get the error message: </SPAN></P><P> </P><P><STRONG>94 95 96 Proc sgplot data = pred; 97 plot p * x_1 = x_2 / vaxis = Axis1 haxis = Axis2; ____ 180 ERROR 180-322: Statement is not valid or it is used out of proper order. </STRONG></P><P> </P><P> </P><P><SPAN>Why is that? How do I solve it? </SPAN></P><P> </P><P><SPAN>I also wonder how I can run the same code for several different samples, lets say 300 different samples. Can I make a loop for this and how do I do that? (SAS® Studio university edition) </SPAN></P><P> </P><P> </P><P> </P><P>PROC IMPORT DATAFILE=REFFILE<BR />DBMS=DBF<BR />OUT=WORK.IMPORT1;<BR />RUN;</P><P><BR />proc freq data = WORK.IMPORT1;<BR />tables x_1*(x_2 ytest);<BR />tables x_2*ytest;<BR />weight num;<BR />run;</P><P>proc tabulate data = WORK.IMPORT1;<BR />class x_1 x_2 ytest;<BR />tables x_1='x_1', ytest*x_2='x_2'*F=6. / rts=13.;<BR />freq num;<BR />run;</P><P>proc logistic data = WORK.IMPORT1 desc;<BR />class x_1 x_2 ytest;<BR />freq num;<BR />model ytest = x_1 x_2;<BR />exact x_1 x_2 / estimate = both;<BR />run;</P><P>proc logistic data = WORK.IMPORT1 desc;<BR />class x_1 x_2 ytest;<BR />freq num;<BR />model ytest = x_1 x_2;<BR />exact x_1 x_2 / estimate = both;<BR />output out = pred predicted = p;<BR />run;</P><P>symbol1 c=blue v=circle i=join;<BR />symbol2 c=red v=plus i=join;<BR />symbol3 c=black v=square i=join;<BR />axis1 label=(r=0 a=90) minor=none;<BR />axis2 minor=none order=(0 1);<BR />proc sgplot data= pred;<BR />plot p*x_1=x_2 / vaxis=axis1 haxis=axis2;<BR />run;<BR />quit;</P>Fri, 07 Apr 2017 15:38:13 GMThttps://communities.sas.com/t5/SAS-Programming/How-do-I-solve-Error-Statement-is-not-valid-or-it-is-used-out-of/m-p/348168#M80591gretaolsson2017-04-07T15:38:13Z