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

Search Actuarial Jobs by State @ DWSimpson.com:
AL AK AR AZ CA CO CT DE FL GA HI ID IL IN IA KS KY LA
ME MD MA MI MN MS MO MT NE NH NJ NM NY NV NC ND
OH OK OR PA RI SC SD TN TX UT VT VA WA WV WI WY

Reply
 
Thread Tools Display Modes
  #41  
Old 02-09-2011, 04:45 PM
ThatGuy's Avatar
ThatGuy ThatGuy is offline
Member
 
Join Date: Aug 2010
College: I'm Old.
Posts: 1,202
Default

Spoiler:
Any chance you can help me get my code to work or should I start working on using your methods for looping? Currently here is where I am

%let mth3=200512;
%macro blah;
%do year = 2006 %to 2010 and mth = 1 %to 12;
%if ((mth=9 and year=2009) or (year=2009 and mth=12) or (year>2009)%then
/* SET LOCATION OF INPUT AND OUTPUT FILES */
%let yearabr = %sysfunc(Right(&year,2));
%If &mth <10 %then
%let al_ext=AL&yearabr.0&mth..vmf;
%else
%let al_ext=AL&yearabr&mth..vmf;

%let hmDIR=E:\Finance\StreamValuation;
%If &mth <10 %then
%let hmVMF=E:\Finance\StreamValuation\&year.0&mth-Stream\VMFs;
%else
%let hmVMF=E:\Finance\StreamValuation\&year&mth-Stream\VMFs;
%else
/* SET LOCATION OF INPUT AND OUTPUT FILES */
%let yearabr = 11;
%If &mth <10 %then
%let al_ext=AL&yearabr.0&mth..vmf;
%else
%let al_ext=AL&yearabr&mth..vmf;

%let hmDIR=R:\Finance\HMCOMBO;
%If &mth <10 %then
%let hmVMF=R:\Finance\HMCOMBO\&year.0&mth-Stream\VMFs;
%else
%let hmVMF=R:\Finance\HMCOMBO\&year&mth-Stream\VMFs;

I can't get the macro to work anymore. But it worked before when I only looped through month....Next post will be my errors

Last edited by ThatGuy; 02-10-2011 at 12:31 PM..
Reply With Quote
  #42  
Old 02-09-2011, 04:46 PM
ThatGuy's Avatar
ThatGuy ThatGuy is offline
Member
 
Join Date: Aug 2010
College: I'm Old.
Posts: 1,202
Default

Spoiler:
ERROR: Macro keyword LET appears as text. A semicolon or other delimiter may be missing.
ERROR: Macro keyword MACRO appears as text. A semicolon or other delimiter may be missing.
ERROR: Macro keyword DO appears as text. A semicolon or other delimiter may be missing.
2836 %let mth3=200512;
ERROR: Macro keyword IF appears as text. A semicolon or other delimiter may be missing.
2837 %macro blah;
2838 %do year = 2006 %to 2010 and mth = 1 %to 12;
ERROR: Macro keyword IF appears as text. A semicolon or other delimiter may be missing.
2839 %if ((mth=9 and year=2009) or (year=2009 and mth=12) or (year>2009)%then
2840 /* SET LOCATION OF INPUT AND OUTPUT FILES */
2841 %let yearabr = %sysfunc(Right(&year,2));
ERROR: There is no matching %IF statement for the %ELSE. A dummy macro will be compiled.
ERROR: Macro keyword LET appears as text. A semicolon or other delimiter may be missing.
2842 %If &mth <10 %then
2843 %let al_ext=AL&yearabr.0&mth..vmf;
ERROR: Macro keyword LET appears as text. A semicolon or other delimiter may be missing.
2844 %else
2845 %let al_ext=AL&yearabr&mth..vmf;
ERROR: Macro keyword IF appears as text. A semicolon or other delimiter may be missing.
2846
2847 %let hmDIR=E:\Finance\StreamValuation;
ERROR: There is no matching %IF statement for the %ELSE. A dummy macro will be compiled.
ERROR: Macro keyword LET appears as text. A semicolon or other delimiter may be missing.
2848 %If &mth <10 %then
2849 %let hmVMF=E:\Finance\StreamValuation\&year.0&mth-Stream\VMFs;
ERROR: There is no matching %IF statement for the %ELSE. A dummy macro will be compiled.
2850 %else
ERROR: Macro keyword LET appears as text. A semicolon or other delimiter may be missing.
2851 %let hmVMF=E:\Finance\StreamValuation\&year&mth-Stream\VMFs;
ERROR: Macro keyword IF appears as text. A semicolon or other delimiter may be missing.
2852 %else
2853 /* SET LOCATION OF INPUT AND OUTPUT FILES */
2854 %let yearabr = 11;
ERROR: There is no matching %IF statement for the %ELSE. A dummy macro will be compiled.
ERROR: Macro keyword LET appears as text. A semicolon or other delimiter may be missing.
2855 %If &mth <10 %then
2856 %let al_ext=AL&yearabr.0&mth..vmf;
ERROR: Macro keyword LET appears as text. A semicolon or other delimiter may be missing.
2857 %else
2858 %let al_ext=AL&yearabr&mth..vmf;
ERROR: Macro keyword IF appears as text. A semicolon or other delimiter may be missing.
2859
2860 %let hmDIR=R:\Finance\HMCOMBO;
ERROR: There is no matching %IF statement for the %ELSE. A dummy macro will be compiled.
ERROR: Macro keyword LET appears as text. A semicolon or other delimiter may be missing.

Last edited by ThatGuy; 02-10-2011 at 12:32 PM..
Reply With Quote
  #43  
Old 02-09-2011, 04:46 PM
ThatGuy's Avatar
ThatGuy ThatGuy is offline
Member
 
Join Date: Aug 2010
College: I'm Old.
Posts: 1,202
Default

If you can help that would be cool...If this is jargon I can delete the posts.
Reply With Quote
  #44  
Old 02-09-2011, 04:57 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,684
Blog Entries: 2
Default

I think instead of
%do year = 2006 %to 2010 and mth = 1 %to 12;
<code>
%end;

you want to have
%do year = 2006 %to 2010;
%do mth = 1 %to 12;
<code>
%end;
%end;


Error log looks as though you've missed a tag somewhere and are stuck within some macro definition or macro code.

To get out of that, submit this code....
*); */; /*'*/ /*"*/; %mend;*); */; /*'*/ /*"*/; %mend;*); */; /*'*/ /*"*/; %mend;*); */; /*'*/ /*"*/; %mend;
__________________
If at first you don't succeed, you have one data point.
Res ipsa loquitur, sed quid in infernos dicet?
Reply With Quote
  #45  
Old 02-09-2011, 05:20 PM
ThatGuy's Avatar
ThatGuy ThatGuy is offline
Member
 
Join Date: Aug 2010
College: I'm Old.
Posts: 1,202
Default

Okay I just kept reopening SAS and rerunning, I got the code a little bit better. I'll wait until tomorrow to post more though.
Reply With Quote
  #46  
Old 02-09-2011, 05:26 PM
dumples dumples is offline
Member
CAS
 
Join Date: Sep 2003
Posts: 1,240
Default

Quote:
Originally Posted by BassFreq View Post
I think you just want
f%SYSFUNC(PUTN(&af_i,z4.))lib.&infile.
In this case, my library was YYMM so I want 1101, that would just be 0001. It would be cool to generalize it so that you could have it be
1101
1102
...
1112
1201
1202

That logic is easy to do in a datastep.
I just ran into a problem putting in one line. SAS is not my forte.
Reply With Quote
  #47  
Old 02-09-2011, 06:17 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,684
Blog Entries: 2
Default

Quote:
Originally Posted by dumples View Post
In this case, my library was YYMM so I want 1101, that would just be 0001. It would be cool to generalize it so that you could have it be
1101
1102
...
1112
1201
1202

That logic is easy to do in a datastep.
I just ran into a problem putting in one line. SAS is not my forte.
Check your log after running this code:
Code:

%macro test;
 %do year = 2006 %to 2010;
   %do mth = 1 %to 12;
     %let ccyymm=%eval(&year*100+&mth);
     %put &ccyymm;
   %end;
 %end;
%mend;
 
%test;
__________________
If at first you don't succeed, you have one data point.
Res ipsa loquitur, sed quid in infernos dicet?
Reply With Quote
  #48  
Old 02-10-2011, 10:37 AM
ThatGuy's Avatar
ThatGuy ThatGuy is offline
Member
 
Join Date: Aug 2010
College: I'm Old.
Posts: 1,202
Default

Any thoughts on why my If else statement isn't working?
Spoiler:

%if ((mth=9 and year=2009) or (year=2009 and mth=12) or (year>2009)) %then/* SET LOCATION OF INPUT AND OUTPUT FILES */
%do;
%let yearabr = %sysfunc(substr(&year,3,2));
%If &mth <10 %then
%let al_ext=AL&yearabr.0&mth..vmf;
%else
%let al_ext=AL&yearabr&mth..vmf;

%let hmDIR=E:\***;
%If &mth <10 %then
%let hmVMF=E:\***\&year.0&mth-Stream\VMFs;
%else
%let hmVMF=E:\***\&year&mth-Stream\VMFs;
%end;
%else/* SET LOCATION OF INPUT AND OUTPUT FILES */
%do;
%let yearabr = %sysfunc(substr(&year,3,2));
%If &mth <10 %then
%let al_ext=AL&yearabr.0&mth..vmf;
%else
%let al_ext=AL&yearabr&mth..vmf;

%let hmDIR=R:\***;
%If &mth <10 %then
%let hmVMF=R:\***\&year.0&mth-Stream\VMFs;
%else
%let hmVMF=R:\***\&year&mth-Stream\VMFs;
%end;

Last edited by ThatGuy; 02-10-2011 at 12:32 PM..
Reply With Quote
  #49  
Old 02-10-2011, 10:39 AM
dumples dumples is offline
Member
CAS
 
Join Date: Sep 2003
Posts: 1,240
Default

BassFreq, thank you for your input. It helped me come up with this:
(sorry that the AO kills the tabbing)
Spoiler:
Code:
%Let rootFolder = /sas/sasusers/dumples/;
%Let valdate = %sysfunc(MDY(1,1,2011));
%Macro Declarelibs(dl_Start=,dl_Stop=);
%IF &dl_START LE &dl_Stop %THEN%DO;
%Do dl_i = &dl_Start %to &dl_Stop;
DATA _null_;
valdate2 = intnx("month",&valdate, &dl_i);
LENGTH valYYMM $4.;
valYYMM = substr(PUT(year(valdate2),z4.),3,2)||PUT(month(valdate2),z2.);
call symput('valYYMM',valYYMM);
RUN;
libname f&valyymm.lib %Sysfunc(QUOTE(&Rootfolder.f&valyymm.));
%END; *End of Loop;
%END; *End of IF statement;
%Mend DeclareLibs;
%Declarelibs(dl_start = 0, dl_stop = 1);run;
%MACRO AppendFiles(af_outLib=,af_OutFile=, af_inFile=, af_Start=, af_Stop=); 
%IF &af_START LE &af_Stop %THEN%DO;
DATA &af_outLib..&af_outFile.; 
SET 
%DO af_i = &af_Start %TO &af_Stop;
%LET valdate2 = %SYSFUNC(intnx(month,&valdate, &af_i));
%LET af_lib = %EVAL((100*%SYSFUNC(MOD(%SYSFUNC(year(&valdate2)),100))+%SYSFUNC(month(&valdate2))));
f%SYSFUNC(PUTN(&af_lib,z4.))lib.&af_infile.
%END; 
; /* this additional ';' is necessary, the first ';' is for the '%END', while the second ';' is for 'SET' */
RUN; 
%END; *End of IF statement;
%MEND AppendFiles;
%AppendFiles(af_outLib= work,af_OutFile= test, af_inFile=test , af_Start=0, af_Stop=1); 


I think this, while it is more complicated, is a bit more elegant as well. Here, you give it a starting date and tell it how many months you want to run from there. This'll work better than a double loop if you're looking at a fixed window, say 60 months, for a date (that could come in the middle of a year).

Key observations. When using intnx in a regular datastep, you say
intnx("month",date,number);
when using IntNX in a macro, you say
%SYSFUNC(intnx(month,date,number);
No quotes.

The more you know.
Reply With Quote
  #50  
Old 02-10-2011, 10:42 AM
dumples dumples is offline
Member
CAS
 
Join Date: Sep 2003
Posts: 1,240
Default

Quote:
Originally Posted by ThatGuy View Post
Any thoughts on why my If else statement isn't working?

%if ((&mth=9 and &year=2009) or (&year=2009 and &mth=12) or (&year>2009)) %then/* SET LOCATION OF INPUT AND OUTPUT FILES */
%do;
%let yearabr = %sysfunc(substr(&year,3,2));
%If &mth <10 %then
%let al_ext=AL&yearabr.0&mth..vmf;
%else
%let al_ext=AL&yearabr&mth..vmf;

%let hmDIR=E:\***;
%If &mth <10 %then
%let hmVMF=E:\***\&year.0&mth-Stream\VMFs;
%else
%let hmVMF=E:\***\&year&mth-Stream\VMFs;
%end;
%else/* SET LOCATION OF INPUT AND OUTPUT FILES */
%do;
%let yearabr = %sysfunc(substr(&year,3,2));
%If &mth <10 %then
%let al_ext=AL&yearabr.0&mth..vmf;
%else
%let al_ext=AL&yearabr&mth..vmf;

%let hmDIR=R:\***;
%If &mth <10 %then
%let hmVMF=R:\***\&year.0&mth-Stream\VMFs;
%else
%let hmVMF=R:\***\&year&mth-Stream\VMFs;
%end;
Does this do it?
Reply With Quote
Reply

Thread Tools
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 08:20 PM.


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