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

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

....

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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;

View solution in original post

5 REPLIES 5
Patrick
Opal | Level 21

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;

SeanZ
Obsidian | Level 7

Thank you. But is it possible to list what are they? And what (*) means here?

Patrick
Opal | Level 21

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.

jakestat
Obsidian | Level 7

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?

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!

How to Concatenate Values

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.

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
  • 5 replies
  • 23885 views
  • 3 likes
  • 3 in conversation