Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- SAS Procedures
- /
- Recording number of observations by group using PROC FREQ

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 02-18-2016 03:32 PM
(1032 views)

I am very new to SAS and am looking for help with a very basic task.

I have figured out how to count the number of observations in a dataset by group, or to display the counts using proc freq. How would I go about storing the information (for example, number of observations coming from group 4) so that I can use it later on? For example, if I determined that 134 observations come from group 4, how could I store this information so that I can use the number later on in some computations? Could I do this simultaneously for the counts coming from all groups?

Is there a way to do this with proc freq? Is there a basic way to do it without this procedure?

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Use the OUT option in the TABLES statement

```
proc freq data=sashelp.class noprint;
table age/out=num_age;
run;
proc print data=num_age;
run;
```

4 REPLIES 4

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Use the OUT option in the TABLES statement

```
proc freq data=sashelp.class noprint;
table age/out=num_age;
run;
proc print data=num_age;
run;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks, that makes sense.

A followup question: say our data had age as a categorical variable (1 if someone is age 10-19, 2 if age is 20-29, etc). Is there a way I can use the value of the number of those with age=2 in computations, by writing something like "num_age[2]"?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I don't think so.

There are other short cuts that can be used, look up SAS variable lists and short cuts.

Arrays are also good to know.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@sasman wrote:

Thanks, that makes sense.

A followup question: say our data had age as a categorical variable (1 if someone is age 10-19, 2 if age is 20-29, etc). Is there a way I can use the value of the number of those with age=2 in computations, by writing something like "num_age[2]"?

You might consider expanding on exactly what you are attempting, what some input data would look like and the desired output. That would be a significantly different post and you should ask a separate question with an appropriate title. The type of numeric computation and what the result could mean would go a long way to providing a cleaner solution.

If the original question has been adequately answered please mark the post gave the answer as the correct solution so others know the original question has been resolved.

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

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.