DATA Step, Macro, Functions and more

Determine and return the number of physical observations in the specified dataset.

Reply
Regular Contributor
Posts: 190

Determine and return the number of physical observations in the specified dataset.

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

Contributor
Posts: 26

Re: Determine and return the number of physical observations in the specified dataset.

Regular Contributor
Posts: 190

Re: Determine and return the number of physical observations in the specified dataset.

thanks but i wanted a custom made code with parameters to do so can u provide 1?
Contributor
Posts: 26

Re: Determine and return the number of physical observations in the specified dataset.

%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 = );

Regular Contributor
Posts: 190

Re: Determine and return the number of physical observations in the specified dataset.

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"
Contributor
Posts: 26

Re: Determine and return the number of physical observations in the specified dataset.

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

 

Rgds,

Abhi

Regular Contributor
Posts: 190

Re: Determine and return the number of physical observations in the specified dataset.

yes i run d code but it did not give the number of obs & is ur macro call correct?!!!
Contributor
Posts: 26

Re: Determine and return the number of physical observations in the specified dataset.

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

Regular Contributor
Posts: 190

Re: Determine and return the number of physical observations in the specified dataset.

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= );
Regular Contributor
Posts: 190

Re: Determine and return the number of physical observations in the specified dataset.

what is RC & IS i couldn't ur logic...
Contributor
Posts: 26

Re: Determine and return the number of physical observations in the specified dataset.

In ur macro call please could you pass the dataset name

 

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

Regular Contributor
Posts: 190

Re: Determine and return the number of physical observations in the specified dataset.

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 : .
Regular Contributor
Posts: 190

Re: Determine and return the number of physical observations in the specified dataset.

what variables are RC & IS ??
Super User
Posts: 7,768

Re: Determine and return the number of physical observations in the specified dataset.

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Regular Contributor
Posts: 190

Re: Determine and return the number of physical observations in the specified dataset.

its a generic macro i don't hav data i need a code which is error free
Ask a Question
Discussion stats
  • 19 replies
  • 313 views
  • 0 likes
  • 7 in conversation