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;
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.
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.
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.
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
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;
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.
I am using that number in an email report
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.