BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kiteulf
Quartz | Level 8

Trying to add a functionalty of writing 0 Count if there are no observations. However it fails on the second else if statement and runs if the else if is commented away....

 

 

Proc freq data=reason ; table remove /out=total_rød_w missing nocol nocum norow nosparse ;


;
run;
Proc datasets nolist;
     contents DATA=work.total_rød_w out=temp(Keep=NOBS) noprint;
run;
Data check;
     Set temp total_rød_w;
     If NOBS = 0 Then do;
			CALL SYMPUT ('Count',PUT(0,10.0));
	 else if NOBS = 1 Then do;
	 		CALL SYMPUT ('Count',PUT(Count,10.0));
	 end;
Run;
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

If that's the sole objective, you can simplify the problem considerably:

 

data _null_;

call symputx('count', '0');

set total_rod_w nobs=_nobs_;

call symputx('count', _nobs_);

stop;

run;

 

If you actually want the same DATA step to write the report when there are 0 observations, slight modifications can make that happen.

View solution in original post

7 REPLIES 7
Kurt_Bremser
Super User

a) you use nobs, but I guess it is never defined, because there is no nobs= option in the set statement.

b) your first then do misses its corresponding end:

data check;
set temp total_red_w; * changed because of special character not allowed in SAS name;
if NOBS = 0
then do;
  call symput ('count',put(0,10.0));
end; * this is missing in your code;
else if NOBS = 1
then do;
  call symput ('count',put(Count,10.0));
end;
run;

For further help, post the log of the data step.

Astounding
PROC Star

If that's the sole objective, you can simplify the problem considerably:

 

data _null_;

call symputx('count', '0');

set total_rod_w nobs=_nobs_;

call symputx('count', _nobs_);

stop;

run;

 

If you actually want the same DATA step to write the report when there are 0 observations, slight modifications can make that happen.

Kiteulf
Quartz | Level 8

I just changed it a bit:

 

data _null_;
call symputx('count', '0');
set pande_total_rød_w nobs=_nobs_;
call symputx('count', COUNT);
stop;
run;

looks like a top soloution

Astounding
PROC Star

You can do something like that, but you have to use the right variable name.  If you want to use COUNT as the variable name in CALL SYMPUTX, you would have to code

 

set have nobs=count;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post exactly what you are doing, trying to do.  I don't see why you wouldn't just access the sashelp.vtable metadata information directly:

data _null_;
  set sashelp.vtable (where=(libname="WORK" and memname="TOTAL_ROD_W"));
  call symput('Count',nobs);
run;

Not that I am entirely sure why you would want to put number of observations into a macro variable in the first place, that sounds like your whole process is a bit off.

Kiteulf
Quartz | Level 8

I am using that number in an email report

RW9
Diamond | Level 26 RW9
Diamond | Level 26

In which case drop the whole macro var bit and just do:

filename mymail ...;
data _null_;
  set set pande_total_rød_w nobs=_nobs_;
  file mymail;
  if _n_=1 then do;
    put "Number of observations: " _nobs_;
  end;
run;

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!

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
  • 7 replies
  • 1248 views
  • 0 likes
  • 4 in conversation