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?
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;
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;
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]"?
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.
@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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.