BookmarkSubscribeRSS Feed
SASInd
Obsidian | Level 7

Hi, 

 

I need to print a count (no. of observations) of a file in a particular field.

How I can achieve that?

 Can I use NOOBS to print in any new field?

 

Thanks

4 REPLIES 4
Kurt_Bremser
Super User

Please supply some example data (in a data step with datalines), and what you expect out of it.

 

noobs is an option for proc print. It will print the observation number in the output.

 

If you want to create a simple observation count, use _n_ in a data step.

Amir
PROC Star

Hi,

 

I'm a little unclear about what you mean by "particular field" and "any new field"; I have assumed that by "file" you mean "SAS data set". Are you trying to create a separate SAS data set that contains the count of observations from another SAS data set? Do you just want to see the count displayed in the log? E.g.:

 

data _null_;
   put count =;
   set sashelp.class(obs=0) nobs = count;
run;

 

Please clarify what you require, thanks.

 

 

Regards,

Amir.

SASInd
Obsidian | Level 7

My file has 5000+ records and I want this no. to be printed in a new file with the records count.

 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Something like:

proc print data=sashelp.vtable;
  var nobs;
  where libname="<yourlib>" and memname="<yourds>";
run;

Note that <yourlib> and <yourds> need to be replaced with your library and dataset names (note most probably in upper case!).

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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