BookmarkSubscribeRSS Feed
GVeers
Calcite | Level 5
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?
4 REPLIES 4
SASKiwi
PROC Star
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.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
Ksharp
Super User
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_;
GVeers
Calcite | Level 5
I did do a search but clearly not the right one! That is amazingly helpful. Thanks guys.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1444 views
  • 0 likes
  • 4 in conversation