I'm fairly new to SAS and very new to macros so I'm hoping I could get some help from fellow SAS users with much more knowledge and experience. I've written code to do exactly what I need, however, the code is based on a single unique variable. There are data sets within the code that are tied to the variable and some data sets merge based on the unique variable. The problem I have is there are 193 more unique variables I need to run this same exact code for.
I've heard of using %do loops within macros but I can't seem to get started without losing my mind. Would someone have some code for a beginner that would get me moving in the right direction?
I'm wondering if I would need to make my code a macro in itself, then create the %do loop macro statement for the unique variable. I can picture it in my head but I can't seem to put it into SAS code.
Any help is greatly appreciated! Many thanks in advance.
Have you looked at the SAS support http://support.sas.com/ technical reference and conference papers, which provide much "free" information and programming techniques / methods.
A Google advanced search such as the one below yields several candidate results:
macro do loop processing site:sas.com
Also, if you are looking to "generate code" from source SAS variable and member names, consider also you may look at using DICTIONARY tables with PROC SQL (or their complimenting SAS views in SASHELP.Vxxxxxxx to work with generating SAS code based on known input data-values (variables, SAS library members, external file names).
Suggested Google advanced search arguments, this topic / post:
I'm a fairly seasoned SAS user and much familiar with macros, so I am hoping I could help out fellow SAS users, but can't. I've heard of *mind reading* and I can't seem to perform it effectively to scan OP's. Any help is greatly appreciated! Many thanks in advance. :-)
Seriously, below is my best guess, which may be totally different from what you are trying to do:
/* create a data set with 194 vars */
retain v001-v194 1;
/* create the data set, some, to be merged in */
retain v001-v194 1 s 2;
/* merge one and some matching on each of v001, v002, ..., v194,
creating datasets merged001, merged002, ... merged194, respectively */
%local out v s;
%let v = v&n;
%let s = s&n;
merge one some(keep=&v s rename=(s=&s));
keep &v &s;
%do i = 1 %to &upto;