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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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