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

 Enter your email to subscribe to DW Simpson weekly actuarial job updates. li.signup { display: block; text-align: center; text-size: .8; padding: 0px; margin: 8px; float: left; } Entry Level Casualty Health Life Pension All Jobs

 Thread Tools Search this Thread Display Modes
#41
02-09-2011, 03:45 PM
 ThatGuy Member Join Date: Aug 2010 College: I'm Old. Posts: 1,202

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 11:31 AM..
#42
02-09-2011, 03:46 PM
 ThatGuy Member Join Date: Aug 2010 College: I'm Old. Posts: 1,202

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 11:32 AM..
#43
02-09-2011, 03:46 PM
 ThatGuy Member Join Date: Aug 2010 College: I'm Old. Posts: 1,202

If you can help that would be cool...If this is jargon I can delete the posts.
#44
02-09-2011, 03:57 PM
 BassFreq Member CAS Join Date: Jun 2003 Location: Chicago Studying for all eternity Favorite beer: Duff Posts: 1,714 Blog Entries: 2

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?
#45
02-09-2011, 04:20 PM
 ThatGuy Member Join Date: Aug 2010 College: I'm Old. Posts: 1,202

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.
#46
02-09-2011, 04:26 PM
 dumples Member CAS Join Date: Sep 2003 Posts: 1,251

Quote:
 Originally Posted by BassFreq 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.
#47
02-09-2011, 05:17 PM
 BassFreq Member CAS Join Date: Jun 2003 Location: Chicago Studying for all eternity Favorite beer: Duff Posts: 1,714 Blog Entries: 2

Quote:
 Originally Posted by dumples 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?
#48
02-10-2011, 09:37 AM
 ThatGuy Member Join Date: Aug 2010 College: I'm Old. Posts: 1,202

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 11:32 AM..
#49
02-10-2011, 09:39 AM
 dumples Member CAS Join Date: Sep 2003 Posts: 1,251

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.
#50
02-10-2011, 09:42 AM
 dumples Member CAS Join Date: Sep 2003 Posts: 1,251

Quote:
 Originally Posted by ThatGuy 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?

 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 01:05 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

Copyright ©2000 - 2019, 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.33298 seconds with 10 queries