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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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
  • 4 replies
  • 756 views
  • 0 likes
  • 4 in conversation