I'm having a little bit of problem with some mapping ,and I'm hoping someone can help me.
Below are 2 example data sets. what I'd like to do is select columns from data2 that appear as datalines for the variable var in data1 (ie var0, var1, var2) from data2, deleting the rest (in this case var44). So far I've been playing around with Symput, but I can't seem to figure anything out.
length var $ 32;
length var_SB $ 32;
var $ var_SB $
FORMAT var $32.;
INFORMAT var $32.;
FORMAT var_SB $32.;
INFORMAT var_SB $32.;
var0 var1 var2 var44;
1 2 3 4
2 4 6 8
1 1 1 1
2 3 4 3
1 1 1 1
There's no need to involve macro variables. Investigate using either PROC SQL with a JOIN or possibly using a DATA step (against your two files sorted by a common variable BY list) and use a MERGE with a BY list of variables -- and on the MERGE statement you would use the IN= dataset option to detect when one or both files contributed a particular observation during the merge process.
Suggested Google advanced search argument, this topic / post:
I've spent a couple of hours playing around with this and I've finally come up with a solution, detailed below for anyone who has the same problem. For some reason the do loop had to be inside a macro.
@sbb, I'm not entirely sure where you're coming from because the merge and the proc sql join rely on me having the headings in data1 as var0 var1 etc, rather than in the datalines. Feel free to correct me if I'm not getting the jist.
set variables end=last;
call symput ('var'!!left(_N_),compress(var));
call symput ('var_SB'!!left(_N_),compress(var_SB));
if last then call symput ('var_count',_N_);
keep %do i=1 %to &var_count;
You can avoid the macro by making a macro variable that is a list of the words in VAR. This will work as long as the list is not longer than the maximum length of a macro variables, about 64k as I recall. Should suffice for most problems.
@ data_null_: This is something that I've been doing previously, and it did work. The reason that we're looking to do it directly from a data step is that we need the mapping between var and var_SB for another purpose.