BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasman
Calcite | Level 5

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
Reeza
Super User

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

4 REPLIES 4
Reeza
Super User

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;
sasman
Calcite | Level 5

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

Reeza
Super User

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.

ballardw
Super User

@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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 1146 views
  • 0 likes
  • 3 in conversation