I use relatively fixed patterns in my SAS programming life. For so called data driven programming (or dynamic programming), I used the following 4 techniques, chronologically: macro array call execute list processing for each loop For a quick demo, I will start with a simple scenario in which the data set sashelp.zipcode should be spitted […]
Tag: macro
Yet Another Instance of DoW-Loop
Just got another DoW-Loop example from SAS Sample #48582:
http://support.sas.com/kb/48/582.html
List Processing With SAS (1): List Creating I
Suppose you have 10 datasets, literally ds1, ds2, …ds10 and you need to concatenate them all. You may first get a quick shortcut set ds1-ds10. If such list members were generated dynamically (and may hold a form like ds1a, ds2a,… ds10a) , you will probably come out a macro solution: %macro doit; data […]
List Processing With SAS: A Github Repository
I have a function like macro (recursive version) to create a sequence: %macro _list(n,pre=ff); %if &n=1 %then &pre.1; %else %_list(%eval(&n-1)),&pre.&n; %mend _list; %put %_list(3); *produces ff1, ff2, ff3; But when I read one of Ian Whitlock’s papers, Names, Names, Names – Make Me a List (SGF 2007, SESUG 2008), I say: stop! I’m […]
Localize Your Macro Variable? Mostly Not Needed or Do It If You Only Want to Initiate It
A piece of SAS codes to create a list of all variables within a dataset (a nice programming trick from Art Carpenter, 2004): %macro getvars(dset) ; %local varlist ; %let fid = %sysfunc(open(&dset)) ; %if &fid %then %do ; %do i=1 %to %sysfunc(attrn(&fid,nvars)) ; %let varlist= &varlist %sysfunc(varname(&fid,&i)); %end […]
NOTE: Ampersands Again
My recent post on double and triple ampersands in macros ended with some doubt. Laurie and Dave immediately took up the challenge to resolve the doubt. You can see the whole painful saga in the comments of the original post, but I’ve repeated Dave’s…
NOTE: The Dreaded Double and Triple Ampersands
Aside from Chris Hemedinger’s comment on SAS V9.3’s PROC SQL INTO enhancements, my Macro Arrays, Straight From a Data Set article last week also caught the attention of another friend and regular correspondent – LeRoy Bessler. LeRoy emailed m…
NOTE: SQL INTO, Revisited
In Macro Arrays Straight From a Data Set last week I wrote about using SQL’s INTO in order to create macro variables (and arrays of macro variables) from PROC SQL. I said that we had to use an arbitrarily large number to define the maximum size of the …