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.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.