join - Joining two tables based on observations in a seperate table (in EG)? -


in enterprise guide, have table (called, countries) containing name of countries of world in 1 column, , currency of country in second column.

e.g.

ctry | crncy ------------------------ uk     | gbp      | usd  fr     | eur  au     | aud 

etc

this table small subset of countries in world, , ranges anywhere between 10 20 observations depending on preference. number of entries in table can change @ time.

for each country specified in countries, have table containing information country, (e.g. example above, have tables called ctry_uk, ctry_us, ctry_fr, ctry_au, etc) , same goes currencies (so have crncy_gbp, crncy_eur, etc)

now each observation in countries, example (uk , gbp), want join ctry_uk table crncy_gbp table, don't know way of doing in sas.

in other words, want join 2 tables based on entries given in seperate table. how can done?

you can read data values macro variables using call open , call set functions, , write whatever code need using macro variables.

%macro combine;     ** open countries data in input mode;     %let dsid = %sysfunc(open(countries, i));     ** set reading of values macro variables of same name;     %syscall set(dsid);     ** read first observation;     %let rc = %sysfunc(fetch(&dsid));      %do %while (&rc = 0);         ** merge data sets using auto-filled &cntry , &crncy macro variables;         data merged_&cntry;             merge cntry_&cntry crncy_&crncy;             id;         run;         ** read next observation;         %let rc = %sysfunc(fetch(&dsid));     %end;     ** close data set;     %let rc = %sysfunc(close(&dsid)); %mend;  **  actual macro call; %combine 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -