Actuarial Outpost Simple SAS Questions
 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

 Salary Surveys Property & Casualty, Life, Health & Pension Health Actuary JobsInsurance & Consulting jobs for Students, Associates & Fellows Actuarial Recruitment Visit DW Simpson's website for more info. www.dwsimpson.com/about Casualty JobsProperty & Casualty jobs for Students, Associates & Fellows

#31
02-09-2011, 12:47 PM
 ThatGuy Member Join Date: Aug 2010 College: I'm Old. Posts: 1,202

okay I will work on the macro step....Can you explain the %mend? I'll give you an update after I fill in some things and screw it up...
#32
02-09-2011, 01:03 PM
 ThatGuy Member Join Date: Aug 2010 College: I'm Old. Posts: 1,202

Okay I almost got the loop working, but for the numbers:

I am using, and when I refer to the month I need it to be in the format 01, how do I ensure this?

%do mth = 01 %to 12;
#33
02-09-2011, 01:22 PM
 dumples Member CAS Join Date: Sep 2003 Posts: 1,250

This is a little hard to explain when to use one thing and not another, but here a two code snippets that should be helpful.

PUT(&i,z2.)
%SYSFUNC
(PUTN(&i,z2.))

I'll post more later, I just have some more work to do right now.
#34
02-09-2011, 01:40 PM
 ThatGuy Member Join Date: Aug 2010 College: I'm Old. Posts: 1,202

modified using If mth <10
%let subdirectory with 0 before mth
else
subdirectory without 0...

easy fix...(sorry this prolly makes little sense)
#35
02-09-2011, 01:43 PM
 ThatGuy Member Join Date: Aug 2010 College: I'm Old. Posts: 1,202

Good to hear all the different ways to do the same thing!
#36
02-09-2011, 02:33 PM
 dumples Member CAS Join Date: Sep 2003 Posts: 1,250

Ok, so the setup here is that I have a library called dLib which is my main folder. In that folder, I have two other folders f1101 and f1102 and I want to create libname statements for those 2 directories

essentially i want to write
Spoiler:

Code:
```
libname f1101 '/sas/sasusers/dumples/f1101';
libname f1102 '/sas/sasusers/dumples/f1102';```

Spoiler:

Code:
```
libname dLib '/sas/sasusers/dumples/';run;
%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;
```
#37
02-09-2011, 02:37 PM
 dumples Member CAS Join Date: Sep 2003 Posts: 1,250

So that prior thing should've just created the library references, now you need to append your tables. Here's what you need to do to append your tables together. I haven't finished this, the stuff that is hard coded in red needs to be changed to a formula.

Spoiler:

Code:
```
%MACRO AppendFiles(af_outLib=,af_OutFile=, 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;
f%SYSFUNC(PUTN(1101,z4.))lib.&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, inFile=test , af_Start=0, af_Stop=1);```
#38
02-09-2011, 02:42 PM
 dumples Member CAS Join Date: Sep 2003 Posts: 1,250

I can't get the formatting correct on the AO, here's a screen shot.

Hope this helps.
Attached Images

#39
02-09-2011, 02:59 PM
 BassFreq Member CAS Join Date: Jun 2003 Location: Chicago Studying for all eternity Favorite beer: Duff Posts: 1,709 Blog Entries: 2

I think you just want
f%SYSFUNC(PUTN(&af_i,z4.))lib.&infile.
__________________
If at first you don't succeed, you have one data point.
Res ipsa loquitur, sed quid in infernos dicet?
#40
02-09-2011, 03:03 PM
 ThatGuy Member Join Date: Aug 2010 College: I'm Old. Posts: 1,202

Possibly I will improve my rag tag coding in the future with your elite efforts.