BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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.
1 REPLY 1
data_null__
Jade | Level 19
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]

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 618 views
  • 0 likes
  • 2 in conversation