Hi I've just started using macros in SAS so I apologize if my question is too simple.. I have a dataset containing something like this: id kom1995 kom1996 kom1997 kom1998 kom1999 kom2000 kom2001 kom2002 ... kom2013 1 45 45 45 45 45 48 48 48 ... 48 2 ... ... ... 48 . . . n 47 47 47 47 47 47 47 47 ... 47 which really isn't the core of my question, but anyway nice to have in mind. My big dataset above is called kommune_s. So, I have a timeseries spanning 18 years. I want 17 smaller datasets containing: Name of dataset 1: kom1995-1996 id kom1995 kom1996 1 45 45 2 ... . . . n 47 47 Name of dataset 2: kom1996-1997 id kom1996 kom1997 1 45 45 2 ... . . . n 47 47 Name of dataset 17: kom2012-2013: id kom2012 kom2013 1 45 45 2 ... . . . n 47 47 OK, sorry for the long text. What I thought that I was able to do was to have SAS make these 17 datasets using a macro and the above dataset kommune_s Something like this: %macro year; %do year=1996 %to 2013; data komlag(&year.)to&year.; set kommune_s; keep id komlag(&year.) kom&year.; run; %end; %mend; %year; Obviously I'm doing something wrong, but I haven't quite figured the macro-feature out yet. I really hope that there is someone who understands my question and is able to help me. Kind regards Christoffer
... View more