Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count distinct of the concatenation/cross of two variables in SAS Proc Sql?

Tags:

sas

proc-sql

I know in teradata or other sql platforms you can find the count distinct of a combination of variables by doing:

select count(distinct x1||x2) from db.table

And this will give all the unique combinations of x1,x2 pairs.

This syntax, however, does not work in proc sql.

Is there anyway to perform such a count in proc sql?

Thanks.

like image 472
Joe Laert Avatar asked Dec 14 '22 13:12

Joe Laert


1 Answers

That syntax works perfectly fine in PROC SQL.

proc sql;
  select count(distinct name||sex)
    from sashelp.class;
quit;

If the fields are numeric, you must put them to character (using put) or use cat or one of its siblings, which happily take either numeric or character.

proc sql;
  select count(distinct cats(age,sex))
    from sashelp.class;
quit;
like image 141
Joe Avatar answered Apr 30 '23 22:04

Joe