Hi, You can transpose your data in single column with country/year combo and then check and count non-missing pairs. Hope the following code will help what you are seeking for. Data table Z will contain all the variable names along with non-missing country/year combo count. data x; infile datalines dsd dlm=' '; input country : $9. year var1 var2 var3 var1330; datalines; Andora 1990 . 5 . 10 Andora 2010 3 7 . . Aruba 1990 4 8 6 9 Aruba 2010 . 4 5 . Argentina 1990 . 5 . 14 Argentina 2010 3 3 . . ; run; *count country year combo to check at later stage; proc sql; create table count as select distinct country, count(distinct year) as c_year from x group by country; quit; * Transpose data to get all values in single column; proc sort data=x; by country year; run; proc transpose data=x out=y name=varnm; by country year; var var:; run; *Merge with count country/year combo information; proc sql; create table y2 as select a.*, b.c_year from y as a left join count as b on a.country = b.country; *Perform final check and count to get per variable available combo; create table z as select distinct a.varnm, sum(a.mark) as final_count from (select distinct varnm, country, count(col1) as count, c_year, case when calculated count = c_year then 1 else 0 end as mark from y2 group by varnm, country) AS a group by varnm order by final_count descending; quit; Thanks
... View more