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
  #181  
Old 08-21-2014, 10:57 AM
Gareth Keenan's Avatar
Gareth Keenan Gareth Keenan is offline
Member
CAS
 
Join Date: Feb 2006
Location: Garden State
Studying for #9
Favorite beer: butter
Posts: 1,308
Default

Quote:
Originally Posted by McBride View Post
Let me ask this. Why do you want to know the location of the 2nd or 3rd occurrence? Are you trying to parse the string into three separate strings or do you just need a count of certain characters?

Regarding your Excel question. I think what you are wanting to may be possible, or at least something close. Do a Google search for "SAS Proc Export Excel Named Range" and see if that helps. You could also try posting your question in communities.sas.com. Sometimes they will even write the code for you!
Firstly, thanks for the other forum recommendation! I have generally had a very favorable experience on Actuarial Outpost asking technical questions for SAS, VB, or just about anything. What I like about the AO interface is that it is simple. Just one place for all of my questions, so as a user it is very easy to use. What intimidates and discourages me from using other forums is partially what discourages me from using the SAS Help, you have to have a decent knowledge base to understand how to use the SAS help, it's not very user friendly. Like wise, with other SAS or excel forums I've seen, there's all of these subcategories and frankly I don't know enough about the nature of my questions to know where to post, and I don't want to get yelled at by the admins for "your post is in the wrong place!" "your post isn't in the right format!" What I need is help. Clean and simple, and there's a burden on other forums that you have to have such a knowledge base before you can even ask. It's suffocating to overstate the problem. So I typically refer to my beloved Actuarial Outpost. But i'll give the official SAS forums another shot.

Onto your other question, why? Because I need to split the data in one column into a few other columns of data for work. Now, in my real world example, I'm not looking to parce out one column of name to three columns of first, middle, and last name, but the example is apt because first and middle names could be of various character lengths. It occurs to me now that instead of using substr, I could use the function that scans for words and define the thing that separates words to be the underscore. I think the function is SCAN? But to actually answer your question, if I know the location of the second and third underscore etc, I can tell the substr function where to start, and how many characters to go.

Thanks for your feedback McBride and Whiskey!
Reply With Quote
  #182  
Old 08-21-2014, 01:35 PM
McBride McBride is offline
Member
CAS SOA
 
Join Date: Oct 2006
Posts: 73
Default

Yes, I understand about the other forums. Some people do tend to be a little full of themselves.

Okay, good, I was hoping you were wanting to parse the column!

You are correct, SCAN should do what you are wanting. The nice thing about SCAN is you just tell it the delimiter and to pull the 1st part, the 2nd part, etc. and you don't have to worry about the length. It figures that out on it's own. Here is something that talks about it. http://www2.sas.com/proceedings/forum2007/035-2007.pdf

If the number of delimiters in your column vary, you can use do looping and arrays to minimize your coding.http://support.sas.com/resources/pap...9/155-2009.pdf
Reply With Quote
  #183  
Old 08-25-2014, 01:28 PM
SpaceActuary's Avatar
SpaceActuary SpaceActuary is offline
Member
 
Join Date: Apr 2010
College: Drake U
Posts: 602
Default

Quote:
Originally Posted by Pikachu View Post
Why does "OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;" keep popping up in my log?
Check your autoexec.sas files. SAS automatically runs the file "autoexec.sas" in your home folder.

Also, are you using SAS Enterprise Guide? If so, check out Tools > Options > Tasks. Under "Custom Code" you might have something that inserts the above options before tasks/queries.
__________________
And all this science, I don't understand; It's just my job five days a week...a rocket man, a rocket man...

"I'm from Iowa. I only work in space." - Adm. James T. Kirk
Reply With Quote
  #184  
Old 08-25-2014, 02:01 PM
SpaceActuary's Avatar
SpaceActuary SpaceActuary is offline
Member
 
Join Date: Apr 2010
College: Drake U
Posts: 602
Default

Quote:
Originally Posted by Gareth Keenan View Post
Okay, last week's question was a no go, perhaps this week will be different.

Simple question, how can I determine the location of the 2nd (or 3rd, 4th, etc) incidence of a character in a character string.

Index is great for finding the first incidence, but is there an easy way to find the second?

For example, I want SAS to return the location of the second underscore for the following text string "Fname_Mname_Lname", how would I do that?

Would I need to embed a substr and index in index? Like find the starting point of the first underscore, start my new variable from there, then find the location of the second underscore? Does that make sense?
Code:
data example;

    text = "Fname_Mname_Lname";
    delim = [COLOR="rgb(153, 50, 204)"]"_"[/color];

    *** The FINDC function and the INDEXC function both search ;
    *** for individual characters in a character string. ;
    *** However, the INDEXC function does not have ;
    *** the modifier nor the startpos arguments. ;
    findc_pos_1 = findc(text, delim);                   *** 6 ; 
    findc_pos_2 = findc(text, delim, findc_pos_1 + 1);  *** 12 ;
    findc_pos_3 = findc(text, delim, findc_pos_2 + 1);  *** 0 ;

    *** the SCAN function does both the finding and substr-ing for you. ;
    scan_word_1 = scan(text, 1, delim);                 *** "Fname" ;
    scan_word_2 = scan(text, 2, delim);                 *** "Mname" ;
    scan_word_3 = scan(text, 3, delim);                 *** "Lname" ;

    *** putting in a negative startpos searches the string backwards. ;
    scan_word_min1 = scan(text, -1, delim);             *** "Lname" ;
    scan_word_min2 = scan(text, -2, delim);             *** "Mname" ;

run;
__________________
And all this science, I don't understand; It's just my job five days a week...a rocket man, a rocket man...

"I'm from Iowa. I only work in space." - Adm. James T. Kirk
Reply With Quote
  #185  
Old 08-25-2014, 02:32 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,716
Blog Entries: 2
Default

You could also do this using Perl regular expressions with the functions whose names start with prx, like prxparse and prxchange.
__________________
If at first you don't succeed, you have one data point.
Res ipsa loquitur, sed quid in infernos dicet?
Reply With Quote
  #186  
Old 08-27-2014, 11:13 PM
McBride McBride is offline
Member
CAS SOA
 
Join Date: Oct 2006
Posts: 73
Default

Quote:
Originally Posted by Pikachu View Post
Are any chapters in Learning SAS by Example important particularly to actuaries?
Truthfully it really depends on your job and/or the kind of data and systems you are working with. In my job, I've used something out of almost every chapter of that book.
Reply With Quote
  #187  
Old 09-22-2014, 03:39 PM
Pujols4Prez's Avatar
Pujols4Prez Pujols4Prez is offline
Member
SOA AAA
 
Join Date: Jul 2008
Posts: 13,872
Default

Okay SAS experts, I have an easy one. I am fitting a bunch of data sets to a Gamma distribution by using Proc Univariate. After I fit the distributions, though, I need to actually use the fitted parameters. SAS gives these in the summary, but I actually need them in some useable format so that I can plug them back into the program. Any thoughts?
__________________
Hardwork is the crutch of the talent-less.

Quote:
Originally Posted by Statatak View Post
what's a JAS
Reply With Quote
  #188  
Old 09-22-2014, 05:41 PM
SpaceActuary's Avatar
SpaceActuary SpaceActuary is offline
Member
 
Join Date: Apr 2010
College: Drake U
Posts: 602
Default

Quote:
Originally Posted by Pujols4Prez View Post
Okay SAS experts, I have an easy one. I am fitting a bunch of data sets to a Gamma distribution by using Proc Univariate. After I fit the distributions, though, I need to actually use the fitted parameters. SAS gives these in the summary, but I actually need them in some useable format so that I can plug them back into the program. Any thoughts?
Code:
data Plates;
   label Gap = 'Plate Gap in cm';
   input Gap @@;
   datalines;
0.746  0.357  0.376  0.327  0.485 1.741  0.241  0.777  0.768  0.409
0.252  0.512  0.534  1.656  0.742 0.378  0.714  1.121  0.597  0.231
0.541  0.805  0.682  0.418  0.506 0.501  0.247  0.922  0.880  0.344
0.519  1.302  0.275  0.601  0.388 0.450  0.845  0.319  0.486  0.529
1.547  0.690  0.676  0.314  0.736 0.643  0.483  0.352  0.636  1.080
;
run;

title 'Distribution of Plate Gaps';
ods select ParameterEstimates GoodnessOfFit FitQuantiles MyHist;
ods output ParameterEstimates=work.fitted_params;
proc univariate data=Plates;
   var Gap;
   histogram / midpoints=0.2 to 1.8 by 0.2
               gamma
               vaxis   = axis1
               name    = 'MyHist';
   inset n mean(5.3) std='Std Dev'(5.3) skewness(5.3)
          / pos = ne  header = 'Summary Statistics';
   axis1 label=(a=90 r=0);
run;
__________________
And all this science, I don't understand; It's just my job five days a week...a rocket man, a rocket man...

"I'm from Iowa. I only work in space." - Adm. James T. Kirk
Reply With Quote
  #189  
Old 09-22-2014, 06:00 PM
Pujols4Prez's Avatar
Pujols4Prez Pujols4Prez is offline
Member
SOA AAA
 
Join Date: Jul 2008
Posts: 13,872
Default

Quote:
Originally Posted by SpaceActuary View Post
Code:
data Plates;
   label Gap = 'Plate Gap in cm';
   input Gap @@;
   datalines;
0.746  0.357  0.376  0.327  0.485 1.741  0.241  0.777  0.768  0.409
0.252  0.512  0.534  1.656  0.742 0.378  0.714  1.121  0.597  0.231
0.541  0.805  0.682  0.418  0.506 0.501  0.247  0.922  0.880  0.344
0.519  1.302  0.275  0.601  0.388 0.450  0.845  0.319  0.486  0.529
1.547  0.690  0.676  0.314  0.736 0.643  0.483  0.352  0.636  1.080
;
run;

title 'Distribution of Plate Gaps';
ods select ParameterEstimates GoodnessOfFit FitQuantiles MyHist;
ods output ParameterEstimates=work.fitted_params;
proc univariate data=Plates;
   var Gap;
   histogram / midpoints=0.2 to 1.8 by 0.2
               gamma
               vaxis   = axis1
               name    = 'MyHist';
   inset n mean(5.3) std='Std Dev'(5.3) skewness(5.3)
          / pos = ne  header = 'Summary Statistics';
   axis1 label=(a=90 r=0);
run;
Thanks a bunch.
__________________
Hardwork is the crutch of the talent-less.

Quote:
Originally Posted by Statatak View Post
what's a JAS
Reply With Quote
  #190  
Old 09-23-2014, 10:50 AM
LICENSED TO ILL's Avatar
LICENSED TO ILL LICENSED TO ILL is offline
Member
 
Join Date: Oct 2005
Posts: 937
Default

do you own a personal sas license? I saw it costs like $8,700
__________________
Spoiler:
Quote:
Originally Posted by Loner View Post
Despite his name, LTI is squeaky clean and not harboring any diseases. Physical ones at least.
Quote:
Originally Posted by OddSox View Post
this might be my favorite thread on the AO
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 06:13 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, 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.61707 seconds with 10 queries