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!).

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 1413 views
  • 0 likes
  • 4 in conversation