Actuarial Outpost Simple SAS Questions
 Register Blogs Wiki FAQ Calendar Search Today's Posts Mark Forums Read
 FlashChat Actuarial Discussion Preliminary Exams CAS/SOA Exams Cyberchat Around the World Suggestions

#21
05-31-2010, 07:42 PM
 Trilli@n Join Date: May 2010 Posts: 1
multiple linear regression

I have a model y=beta0+beta1*x1+beta2*x2+eps, eps~N(0.1)
and I need to do two test2:
1. H0:beta1=0
2. H0:beta2=0

Can someone help me to do this in SAS?
Is this correct?

PROC REG DATA = dataset;
MODEL y = x1 x2;
test x1=0 ;
test x2=0;
run;

How can I save p value from each test to a new data set?
#22
06-02-2010, 01:28 PM
 BassFreq Member CAS Join Date: Jun 2003 Location: Chicago Studying for all eternity Favorite beer: Duff Posts: 1,715 Blog Entries: 2

Quote:
 Originally Posted by Trilli@n I have a model y=beta0+beta1*x1+beta2*x2+eps, eps~N(0.1) and I need to do two test2: 1. H0:beta1=0 2. H0:beta2=0 Can someone help me to do this in SAS? Is this correct? PROC REG DATA = dataset; MODEL y = x1 x2; test x1=0 ; test x2=0; run; How can I save p value from each test to a new data set?
All you need is
odsoutput ParameterEstimates=new_data_set;
PROCREGDATA = dataset;
MODEL y = x1 x2;
run;quit;

The p values will be in the column named Probt in the data set named new_data_set.
__________________
If at first you don't succeed, you have one data point.
Res ipsa loquitur, sed quid in infernos dicet?
#23
12-09-2010, 05:40 PM
 Gareth Keenan Member CAS Join Date: Feb 2006 Location: Garden State Studying for #9 Favorite beer: butter Posts: 1,308
two ifs

I want to create a smaller table from a larger table. My larger table has a character variable, let's say it's date. I want to filter with an if statement so that if the value for each entry in the date variable is 01feb2010 or 01april2010, then it will be included in the smaller table. All other entries for the variable date will be deleted and not included.

I know my code starts with

Data small_table;
set large_table;
if datepart(date) eq '01feb2009'd

but don't know how to include the other if statement to finish the data statement code. I'd prefer something like an Excel OR Function. I also understand an "in" may be appropriate.

Cheers,

Gareth Keenan

Suggestions?
#24
12-10-2010, 10:28 AM
 dumples Member CAS Join Date: Sep 2003 Posts: 1,251

You can't use an in statement?

if datepart(date) IN ('01feb2009'd, '01Apr2009'd);

?
#25
12-10-2010, 11:35 AM
 BassFreq Member CAS Join Date: Jun 2003 Location: Chicago Studying for all eternity Favorite beer: Duff Posts: 1,715 Blog Entries: 2

Two other options are
if datepart(date) IN ('01feb2009'd '01Apr2009'd); /* no comma works */

if datepart(date) = '01feb2009'd or datepart(date) = '01APR2009'd;
__________________
If at first you don't succeed, you have one data point.
Res ipsa loquitur, sed quid in infernos dicet?
#26
12-10-2010, 11:36 AM
 BassFreq Member CAS Join Date: Jun 2003 Location: Chicago Studying for all eternity Favorite beer: Duff Posts: 1,715 Blog Entries: 2

Another option:
if datepart(date) = '01feb2009'd then output;
if datepart(date) = '01APR2009'd then output;
__________________
If at first you don't succeed, you have one data point.
Res ipsa loquitur, sed quid in infernos dicet?
#27
12-10-2010, 11:38 AM
 Gareth Keenan Member CAS Join Date: Feb 2006 Location: Garden State Studying for #9 Favorite beer: butter Posts: 1,308

Success! Thanks Dumples!
#28
12-13-2010, 10:45 AM
 dumples Member CAS Join Date: Sep 2003 Posts: 1,251

I just noticed that you're using an IF statement, one thing that you might want to consider for performance is a WHERE statement.

The big plus to a WHERE statement is performance based. As I understand it, SAS will create a record for each dataline that has a true WHERE (if there is no WHERE then every thing is true so every input line is written) and then will delete lines in statements from IF's. (IF A; is logically and calculation-ally equivalent to IF not A then DELETE; ). For big datasets, you'll see a decent time savings.

The downside is that where statements are a little bit more finicky, it won't do data type conversion, so if you're trying to work with numbers stored as text then you'll need to use a PUT or INPUT statement (I always forget which does which). Also, the conditions need to be based on fields that are in the original dataset, so if you're creating a new field during the data step, then you'll need to use an IF statement.

Last edited by dumples; 01-10-2011 at 01:52 PM..
#29
02-09-2011, 10:30 AM
 ThatGuy Member Join Date: Aug 2010 College: I'm Old. Posts: 1,202

I created code that I want to loop through so I can pull data from different directories for different months, how do i loop my code through say from 2010 01 to 2010 12 through some code. I can explain more as needed this is vague...
#30
02-09-2011, 11:27 AM
 BassFreq Member CAS Join Date: Jun 2003 Location: Chicago Studying for all eternity Favorite beer: Duff Posts: 1,715 Blog Entries: 2

Two ways:
First way is with macro.
%macro blah;
%do i = 1 %to 12;
<then do things, referring to &i for number>
%end;
%mend;
%blah;

Second way would be in data step.
data _null_;set whatev;
call execute('proc copy in=a out=b;select table'||_n_);
run;
__________________
If at first you don't succeed, you have one data point.
Res ipsa loquitur, sed quid in infernos dicet?

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off

All times are GMT -4. The time now is 03:22 PM.

 -- Default Style - Fluid Width ---- Default Style - Fixed Width ---- Old Default Style ---- Easy on the eyes ---- Smooth Darkness ---- Chestnut ---- Apple-ish Style ---- If Apples were blue ---- If Apples were green ---- If Apples were purple ---- Halloween 2007 ---- B&W ---- Halloween ---- AO Christmas Theme ---- Turkey Day Theme ---- AO 2007 beta ---- 4th Of July Contact Us - Actuarial Outpost - Archive - Privacy Statement - Top