Help using Base SAS procedures

Recording number of observations by group using PROC FREQ

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Recording number of observations by group using PROC FREQ

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?

 


Accepted Solutions
Solution
‎02-18-2016 11:47 PM
Super User
Posts: 19,870

Re: Recording number of observations by group using PROC FREQ

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;

View solution in original post


All Replies
Solution
‎02-18-2016 11:47 PM
Super User
Posts: 19,870

Re: Recording number of observations by group using PROC FREQ

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;
New Contributor
Posts: 2

Re: Recording number of observations by group using PROC FREQ

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]"?

Super User
Posts: 19,870

Re: Recording number of observations by group using PROC FREQ

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.

Super User
Posts: 11,343

Re: Recording number of observations by group using PROC FREQ


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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 334 views
  • 0 likes
  • 3 in conversation