Actuarial Outpost
 
Go Back   Actuarial Outpost > Actuarial Discussion Forum > Software & Technology
FlashChat Actuarial Discussion Preliminary Exams CAS/SOA Exams Cyberchat Around the World Suggestions


Reply
 
Thread Tools Search this Thread Display Modes
  #71  
Old 11-29-2011, 02:47 PM
ADoubleDot's Avatar
ADoubleDot ADoubleDot is offline
Member
SOA
 
Join Date: Nov 2007
Location: Slightly Dusty South
Studying for the rest of my life
Posts: 37,141
Default



if garth = "Keenan" then
<do stuff>;
else if garth = "ADD" then
<do different stuff>;
else
<do last resort stuff>;

Always starts with if. else-if tells the compiler that its still part of the same if; in other words, in the above if garth were both "Keenan" and "ADD", it would only execute the code for Keenan and then move on out of the entire if statement. Else by itself is the code that is executed if none of the other conditions are true.
__________________
ADoubleDot: I'm an actuarial icon.

**** Juan.
Reply With Quote
  #72  
Old 11-29-2011, 03:22 PM
dumples dumples is offline
Member
CAS
 
Join Date: Sep 2003
Posts: 1,247
Default

Quote:
Originally Posted by Gareth Keenan View Post
Say I have a source body of data.



And I have a SAS query, where I am interested in all records that have "Lunch" as the meal, but I'm only interested in Lunches that are at or equal to Indicator 4, is there a way to do this in SAS and minimize CPU cycles or whatever?

Specifically, I want my oracle search to not even worry about lunches, until it gets to an indicator with a value of 4 then to worry about lunches. I also know that my source data is sorted by indicator, so that the values of the indicator are from smallest to largest.

Is there a way to do this? In the very large data set I am looking at so if I could get the query to start only at the precise indicator, the query would take less time to execute.

I have this statement executing in an elementary data step, but if there is a more efficient way to do this, I would love to hear it. Thanks!

Gareth Keenan
I realize that this post is both old and answered, but I think that even with indexes, you might get a performance boost if you limit the input data set with Obs and FirstObs statements.

Give this a go and let us know if it's any faster.

Spoiler:

Code:

data test;
input a b c;
cards;
1 2 3
4 5 6
7 8 9
10 11 12
;
run;
data test2;
set test(obs=3 firstobs=2);
run;
Reply With Quote
  #73  
Old 11-29-2011, 06:08 PM
Gareth Keenan's Avatar
Gareth Keenan Gareth Keenan is offline
Member
CAS
 
Join Date: Feb 2006
Location: by a pretty big bay
Studying for #9
Favorite beer: butter
Posts: 1,287
Default create more than one variable, single if?

Does anyone know if it is possible to create more than one variable with a single if?

like

If First_letter = 'G' and Last_Letter ='K' then FL='G' and LL='K';
else FL='.' and LL='.';

where I am creating both the variables G and K?

Thanks,

Gareth Keenan
Reply With Quote
  #74  
Old 11-29-2011, 07:04 PM
McBride McBride is offline
Member
CAS SOA
 
Join Date: Oct 2006
Posts: 73
Default

You'll always begin with "If". You'll get an error, or should, if you start with "Else If".

Usually my SAS if statements look like this:

If A = 1 Then B = 10;
Else If A = 2 Then B = 20;
Else B = 9999;


As far as ending in "Else", it's up to you. There is no requirement. I'm a little paranoid, so I often do something like you see in my example of "Else B = 9999" so that I can easily identify the outliers that I wasn't expecting.
Reply With Quote
  #75  
Old 11-29-2011, 07:09 PM
McBride McBride is offline
Member
CAS SOA
 
Join Date: Oct 2006
Posts: 73
Default

Quote:
Originally Posted by Gareth Keenan View Post
Does anyone know if it is possible to create more than one variable with a single if?

like

If First_letter = 'G' and Last_Letter ='K' then FL='G' and LL='K';
else FL='.' and LL='.';

where I am creating both the variables G and K?

Thanks,

Gareth Keenan
You would do it using a Then Do and Else Do statement:

If First_Letter = 'G' AND Last_Letter = 'K' Then Do;
FL = 'G';
LL = 'K';
End;
Else Do;
Call Missing(FL);
Call Missing(LL);
End;

Call Missing sets the value of the variable to missing. You can do it other ways, that's just my preferred method.
Reply With Quote
  #76  
Old 12-13-2011, 11:19 AM
Gareth Keenan's Avatar
Gareth Keenan Gareth Keenan is offline
Member
CAS
 
Join Date: Feb 2006
Location: by a pretty big bay
Studying for #9
Favorite beer: butter
Posts: 1,287
Default Where my log at?

Has anyone had it happen where your log stops updating when you run code? This just happened to me. A coworker suggested I run

*'; *"; *); */; %mend; run;

like 10 times, but the log still doesn't update on the most elementary of data steps. Is there any way to fix this without having to reboot SAS?

Cheers,

Gareth Keenan
Reply With Quote
  #77  
Old 12-13-2011, 12:06 PM
BassFreq's Avatar
BassFreq BassFreq is offline
Member
CAS
 
Join Date: Jun 2003
Location: Chicago
Studying for all eternity
Favorite beer: Duff
Posts: 1,708
Blog Entries: 2
Default

Happens to me too occasionally. The code your coworker suggested helps when you executed unbalanced quotes or unbalanced paranthesis, but won't help when the log shuts down on you. I haven't figured out a solution to it other than to copy my code and data to a safe place before rebooting SAS.
__________________
If at first you don't succeed, you have one data point.
Res ipsa loquitur, sed quid in infernos dicet?
Reply With Quote
  #78  
Old 12-13-2011, 12:55 PM
Ron Weasley's Avatar
Ron Weasley Ron Weasley is offline
Member
CAS AAA
 
Join Date: Oct 2001
Studying for naught.
Favorite beer: Butterbeer
Posts: 8,623
Default

Ditto
Reply With Quote
  #79  
Old 03-07-2012, 09:50 PM
infinity8 infinity8 is offline
Member
SOA
 
Join Date: Oct 2011
Posts: 69
Default

I'm new to SAS, trying to find resources online. I am trying to filter my data set as follows...

data temptable;
set dataset;
where variable1 = 28 and variable2 like 'bri%';
run;

I am getting errors. Does anyone know why? I believe im doing the wildcard stuff wrong.
Reply With Quote
  #80  
Old 03-07-2012, 10:16 PM
Kmc Kmc is offline
Member
SOA AAA
 
Join Date: Jul 2011
Location: Saint Louis, MO
Studying for Nothing!
College: Washington University in St. Louis Alumnus
Favorite beer: Root
Posts: 157
Default

SAS doesn't use the Like operator (except in proc sql). Instead you would do "substr(variable2,1,3)='bri';"
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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:07 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
*PLEASE NOTE: Posts are not checked for accuracy, and do not
represent the views of the Actuarial Outpost or its sponsors.
Page generated in 0.60724 seconds with 10 queries