BookmarkSubscribeRSS Feed
woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

please help,

 

I have one dataset "A" which has one variable "test" which came out with zero observation 

 

i wants to mention it in auto email from SAS to team that "we have &no_of_obs observation for test" but problem is my below macro variable,no_of_obs, is resolving to &no_of_obs only since i have zero observation,

 

is there any work around to resolve it to zero (0)?

 

data _null_;

set a;

call symput("no_of_obs",_n_);

run;

 

5 REPLIES 5
Tom
Super User Tom
Super User

Change the order of the statements.  SAS stops the data step as soon as it reads past the end of the input stream. So the CALL SYMPUT() never runs.

 

data _null_;
  call symputX("no_of_obs",_n_-1);
  set a;
run;
 
PaigeMiller
Diamond | Level 26
%let no_of_obs=0;
data _null_;
set a;
call symput("no_of_obs",_n_);
run;
--
Paige Miller
woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

Thanks Tom, it worked fine, 

 

@ Miller - in my case, its not a case where i will always get 0 obs, could be possible obs>0

 

 

PaigeMiller
Diamond | Level 26

@woo wrote:

@ Miller - in my case, its not a case where i will always get 0 obs, could be possible obs>0

 

 


Yes, the code as I wrote it will produce a result of 0 if there is no data, and a positive number equal to the number of observations when there is a positive number of data points.

--
Paige Miller
Astounding
PROC Star

For efficiency purposes, this sort of problem is usually handled a little differently.  Notice that your original code executes CALL SYMPUT for each observation in the data set.  It that's a million times, you might be slowing the program down.  An alternative:

 

data _null_;

call symputx("no_of_obs", _nobs_);

stop;

set a nobs=_nobs_;

run;

 

Note that switching to CALL SYMPUTX will remove from your log the message about numeric to character conversion, and will remove leading blanks from the value of &NO_OF_OBS.

 

Good luck.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 5 replies
  • 1066 views
  • 1 like
  • 4 in conversation