I always want to count the number of observations/list these observations that meet certain conditions I define. But I don't really know how to do it. For example, I have the following dataset. I want to find # of observations that firm=1 & dummy=B & assets=10, and list those observations. This seems to be easy as a short dataset, but if there are more than 1 million observations, it will be much more difficult. So I wonder if there is any procedure or other command that will run this purpose.
firm date dummy$ assets
1 1 B 100
1 1 S 10
1 2 S 10
....
You could use quite a few SAS Procedures for this (Proc Means/Summary, Proc Report, Proc Tabulate,....).
Here some code using Proc SQL:
proc sql;
select count(*) as N_Obs
from have
where firm=1 and dummy='B' and assets=10
;
quit;
You could use quite a few SAS Procedures for this (Proc Means/Summary, Proc Report, Proc Tabulate,....).
Here some code using Proc SQL:
proc sql;
select count(*) as N_Obs
from have
where firm=1 and dummy='B' and assets=10
;
quit;
Thank you. But is it possible to list what are they? And what (*) means here?
If you have SAS EG then I suggest you use the Query Builder Wizard and "play around" with it until you get the result you want. After that look at the code generated by the wizard and eventually use the SAS Online Doc (Proc SQL) to understand the syntax.
Your questions are very basic so I feel you probably should first invest a bit of time in learning SAS and SQL language.
Thank you
Patrik,
Thank you for this solution. If I could, I wish to know how to assign N_Obs to a macro var such as &nobs or to a universal variable. Is that somthing that can be done within the proc sql?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.