DATA Step, Macro, Functions and more

DataStep and Proc SQL

Reply
N/A
Posts: 0

DataStep and Proc SQL

Hi All,

I have a dataset with approx 30 variables and I want to find out number of unique observation count for each variable

For ex:

data sample;
input empid sal name$;
cards;
101 1000 aaa
102 2000 bbb
103 2000 ccc
104 1000 ddd
run;


proc sql;
create table count as
select count(distinct(empid)) as count_eid,
count(distinct(sal)) as count_sal,
count(distinct(name)) as count_name
from sample;
quit;

the above query results to
4, 2 and 4

My problem is i want to automate the query rather than writing all the 30 variables in select query.

so, please reply me ASAP.
Respected Advisor
Posts: 3,777

Re: DataStep and Proc SQL

Using PROC FREQ the syntax will be more concise.

[pre]
ods select Freq.NLevels;
ods output Freq.NLevels=Nlevels;
proc freq data=sample levels;
run;
ods select all;
Proc print;
run;
[/pre]
Ask a Question
Discussion stats
  • 1 reply
  • 122 views
  • 0 likes
  • 2 in conversation