BookmarkSubscribeRSS Feed
RTelang
Fluorite | Level 6

a generic macro to Determine and return the number of physical observations in the specified dataset.!!!

19 REPLIES 19
RTelang
Fluorite | Level 6
thanks but i wanted a custom made code with parameters to do so can u provide 1?
AbhiD
Obsidian | Level 7

%macro check(dsName = );
%let dsid = %sysfunc(open(&dsName, IS));

%if &DSID = 0 %then
%put %sysfunc(sysmsg());
%let nlobs = %sysfunc(attrn(&dsid,NLOBS));

%put No of Observation in dataset %trim(&dsName) : %trim(&nlobs);

%let rc = %sysfunc(close(&dsid));

%mend;


%check(dsName = );

RTelang
Fluorite | Level 6
dsid, rc, ??? have u defined it, have u run it does it work does it return the number of observations i want the number that's imp. "a macro to determine the number of obs in a data set"
AbhiD
Obsidian | Level 7

Yes it works if you would have ran it you would have known

 

Rgds,

Abhi

RTelang
Fluorite | Level 6
yes i run d code but it did not give the number of obs & is ur macro call correct?!!!
AbhiD
Obsidian | Level 7

can you paste what macro call u used and the log for the same

RTelang
Fluorite | Level 6
options nomprint nomlogic;
%macro check(dsName = );
%let dsid = %sysfunc(open(&dsName, IS));

%if &DSID = 0 %then
%put %sysfunc(sysmsg());
%let nlobs = %sysfunc(attrn(&dsid,NLOBS));
%put No of Observation in dataset %trim(&dsName) : %trim(&nlobs);
%let rc = %sysfunc(close(&dsid));

%mend;

%check(dsName= );
the log

options nomprint nomlogic;
%macro check(dsName = );
%let dsid = %sysfunc(open(&dsName, IS));

%if &DSID = 0 %then
%put %sysfunc(sysmsg());
%let nlobs = %sysfunc(attrn(&dsid,NLOBS));
%put No of Observation in dataset %trim(&dsName) : %trim(&nlobs);
%let rc = %sysfunc(close(&dsid));

%mend;

%check(dsName= );
RTelang
Fluorite | Level 6
what is RC & IS i couldn't ur logic...
AbhiD
Obsidian | Level 7

In ur macro call please could you pass the dataset name

 

%check(dsName= <<YOUR DATASET NAME HERE LIBRARY.DATASETNAME)>> );

RTelang
Fluorite | Level 6
55
56 %let dsName=data1;
57 options nomprint nomlogic;
58 %macro check(dsName= );
59 %let dsid = %sysfunc(open(&dsName, IS));
60
61 %if &DSID = 0 %then
62 %put %sysfunc(sysmsg());
63 %let nlobs = %sysfunc(attrn(&dsid,NLOBS));
64 %put No of Observation in dataset %trim(&dsName) : %trim(&nlobs);
65 %let rc = %sysfunc(close(&dsid));
66
67 %mend;
68
69 %check(dsName=);
ERROR: There is not a default input data set (_LAST_ is _NULL_).
WARNING: Argument 1 to function ATTRN referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.
NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The result of the operations have been set
to a missing value.
No of Observation in dataset : .
Kurt_Bremser
Super User

In

%check(dsName=);

you specifically submitted an empty string to the macro, so no dataset could be found.

Supply a valid dataset name, and the macro will work.

 

Inform yourself about how parameters are passed to macros.

RTelang
Fluorite | Level 6
its a generic macro i don't hav data i need a code which is error free

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 19 replies
  • 3744 views
  • 0 likes
  • 7 in conversation