Actuarial Outpost Simple SAS Questions
 User Name Remember Me? Password
 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

2017 ACTUARIAL SALARY SURVEYS
Contact DW Simpson for a Personalized Salary Survey

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

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.
#72
11-29-2011, 03:22 PM
 dumples Member CAS Join Date: Sep 2003 Posts: 1,247

Quote:
 Originally Posted by Gareth Keenan Say I have a source body of data. $\begin{matrix} Indicator&Meal&Entree \\ 1&Dinner&Poultry \\ 2&Breakfast&Eggs \\ 3&Lunch&Sandwich \\ 4&Lunch&Soup \\ 5&Dinner&Salad \\ 6&Lunch&Left\ Overs \end{matrix}$ 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;

#73
11-29-2011, 06:08 PM
 Gareth Keenan Member CAS Join Date: Feb 2006 Location: by a pretty big bay Studying for #9 Favorite beer: butter Posts: 1,287
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
#74
11-29-2011, 07:04 PM
 McBride Member CAS SOA Join Date: Oct 2006 Posts: 73

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.
#75
11-29-2011, 07:09 PM
 McBride Member CAS SOA Join Date: Oct 2006 Posts: 73

Quote:
 Originally Posted by Gareth Keenan 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.
#76
12-13-2011, 11:19 AM
 Gareth Keenan Member CAS Join Date: Feb 2006 Location: by a pretty big bay Studying for #9 Favorite beer: butter Posts: 1,287
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
#77
12-13-2011, 12:06 PM
 BassFreq Member CAS Join Date: Jun 2003 Location: Chicago Studying for all eternity Favorite beer: Duff Posts: 1,708 Blog Entries: 2

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?
#78
12-13-2011, 12:55 PM
 Ron Weasley Member CAS AAA Join Date: Oct 2001 Studying for naught. Favorite beer: Butterbeer Posts: 8,623

Ditto
#79
03-07-2012, 09:50 PM
 infinity8 Member SOA Join Date: Oct 2011 Posts: 69

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.
#80
03-07-2012, 10:16 PM
 Kmc 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

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

 Thread Tools Search this Thread Search this Thread: Advanced Search Display Modes Linear Mode

 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 02:20 AM.

 -- 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