DATA Step, Macro, Functions and more

how to detect how many obs in one dataset

Accepted Solution Solved
Reply
Super Contributor
Posts: 345
Accepted Solution

how to detect how many obs in one dataset

Someone suggest:

 

proc sql noprint;
select count(*) into Smiley Surprisedbservations from library.dataset;
quit;

 

Would anybody tell me what to do next? Thanks.


Accepted Solutions
Solution
‎09-07-2017 03:37 PM
Super User
Posts: 5,516

Re: how to detect how many obs in one dataset

This creates a macro variable holding the count.  You could write it out:

 

%put &observations;

 

Or a DATA step could use it:

 

n_obs = &observations;

 

When the emoticon replacing your actual code, it's difficult to determine what the exact name of your macro variable is ... &observations, or &n_observations, or something similar.

View solution in original post


All Replies
PROC Star
Posts: 765

Re: how to detect how many obs in one dataset

What is your goal? What do you want to achieve?

Super Contributor
Posts: 345

Re: how to detect how many obs in one dataset

get the total number of obs

Solution
‎09-07-2017 03:37 PM
Super User
Posts: 5,516

Re: how to detect how many obs in one dataset

This creates a macro variable holding the count.  You could write it out:

 

%put &observations;

 

Or a DATA step could use it:

 

n_obs = &observations;

 

When the emoticon replacing your actual code, it's difficult to determine what the exact name of your macro variable is ... &observations, or &n_observations, or something similar.

Super User
Posts: 19,861

Re: how to detect how many obs in one dataset

Try SASHELP.VTABLE or the corresponding dictionary table.

 

proc sql noprint;
select nobs into :nobs_class TRIMMED
from sashelp.vtable 
where libname='SASHELP' and memname='CLASS';
quit;

%put Number of obs = &nobs_class;

 

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 81 views
  • 0 likes
  • 4 in conversation