Simplify, Simplify, Simplify
Simplify, Simplify, Simplify
Simplify, Simplify, Simplify
Start with a simple macro.
%macro dsn(t=,NME=);
%local cnt i value ;
%let cnt = %sysfunc(countw(&t.,%str( )));
%do i = 1 %to &cnt.;
%let value = %scan(&t,&i,%str( ));
%if &value ne 0 %then %do;
%put &=value is not zero ;
%end;
%else %do;
%put &=value is zero ;
%end;
%end;
%mend;
%dsn(t= 0 0 10,nme=SALES1);
Results:
36 %dsn(t= 0 0 10,nme=SALES1); VALUE=0 is zero VALUE=0 is zero VALUE=10 is not zero
Things to fix.
Now that we have a framework for looping over a list of values and testing if any of them is zero can you please explain what SAS code you are trying to use the macro to generate?
Let's make this simple.
You have a dataset looking like this:
Data Sales;
Name $ Product $ Sales1 Sales2 Sales3;
datalines;
aaa xxxxx 0 0 200
dfrt iiiiiiiii 03 05 65
ertttt pxxdfd 55 0 0
;
What do you want to get out of this? A report, a dataset, or multiple reports/datasets?
Just show the end result, then we can go looking for the tools that are best.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.