I all,
I have a problem. I do so as from a table with 100 rows bait a table with rows that have that condition. By turning the macro made sas erases and writes the new data set and then instead of 4 lines provided only one that comes out the end of the dataset.
%macro xxx ();
%do i=1 %to 24;
data _null_;
var="hour"||put(&i,z2.);
call symput('var',var);
run;
data control1;
set control;
%put &var;
if &var eq "AAA" or &var eq "BBB" or &var eq "CCC" then delete;
%end;
run;
%mend xxx;
%xxx;
thank's a lot
bie bie m
Hi Jack,
Can you be somewhat clear about the issue.
You closed the do loop inside the datastep block.
I have a table of 100 rows and 3 columns. who call hour01 hour02 hour03. I try to find in these three columns if data is different from "AAA", "BBB" and "CCC". If it is different then I write in a table. So if there are three lines that read "LLL" I find myself in the new table three lines.
So far, there is no use for macros here. You could easily code:
data want;
set have;
if hour01 not in ('AAA', 'BBB', 'CCC') then output;
else if hour02 not in ('AAA', 'BBB', 'CCC') then output;
else if hour03 not in ('AAA', 'BBB', 'CCC') then output;
run;
Is that close to what you need?
but the 3 columns is an example actually are 24 and may be even 23 or 25
Use an ARRAY instead of macro loop and the WHICHC function.
If you post sample data with expected output your problem will be clearer and we can help you more.
Try posting a datastep with some test data and required output as your logic isn't hard to follow. Why do you need a macro? Why not just do:
data want;
set have;
where col1 in ("aaa","bbb","ccc") or col2 in ("aaa","bbb","ccc") or col3 in ("aaa","bbb","ccc");
run;
You should only use macro logic to generate SAS code when you cannot do what you want with the basic language.
data want ;
set have ;
array hr hour01-hour24 ;
bad=0;
do over hr ;
if hr not in ('AAA','BBB','CCC') then bad=1;
end;
if bad;
run;
thank's a lot, tom
you have been very useful
bie bie
@Jack 1078. Please mark the answer as correct if you have your answer.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.