Help using Base SAS procedures

Count possible values

Reply
Contributor
Posts: 29

Count possible values

I feel like this is a pretty simple question but I can't seem to find a simple answer.

I have a dataset with a large number of variables. For each variable I'd like to know how many possible values it can take on. So if a variable is either '1,' '2,' or 'NA' then the result would be 3 for that variable. And so on for the entire list of variables.

Seems simple enough, but I can't figure out a good way to do it. Any advice out there?
Super User
Posts: 3,254

Re: Count possible values

I suggest you check out the FREQ procedure. While it is more commonly used to do counts of each distinct value of a variable, it can also output a dataset that contains the distinct values of a variable, one per row. So if you count up the number of rows then you will have your answer.
Super Contributor
Super Contributor
Posts: 3,174

Re: Count possible values

The SAS support website http://support.sas.com/ can help - check it's SEARCH facility where you will find SAS-hosted documentation and supplemental topic-related technical / conference material.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

count unique values site:sas.com
Super User
Posts: 10,035

Re: Count possible values

Yes.
@data _null_; has already have an answer in the previous posts.
It is his/her answer.

[pre]
proc freq data=sashelp.class nlevels;
tables _all_ /nocum nopercent;
run;
[/pre]



Ksharp From data _null_;
Contributor
Posts: 29

Re: Count possible values

I did do a search but clearly not the right one! That is amazingly helpful. Thanks guys.
Ask a Question
Discussion stats
  • 4 replies
  • 122 views
  • 0 likes
  • 4 in conversation