Help using Base SAS procedures

sas loop macro

Reply
Occasional Contributor
Posts: 9

sas loop macro

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

Contributor
Posts: 65

Re: sas loop macro

Hi Jack,

Can you be somewhat clear about the issue.

You closed the do loop inside the datastep block.

Occasional Contributor
Posts: 9

Re: sas loop macro

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.

Super User
Posts: 5,085

Re: sas loop macro

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? 

Occasional Contributor
Posts: 9

Re: sas loop macro

but the 3 columns is an example actually are 24 and may be even 23 or 25

Super User
Posts: 17,840

Re: sas loop macro

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.

Super User
Super User
Posts: 7,405

Re: sas loop macro

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;

Super User
Super User
Posts: 6,502

Re: sas loop macro

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;

Occasional Contributor
Posts: 9

Re: sas loop macro

thank's a lot, tom

you have been very useful

bie bie

PROC Star
Posts: 1,562

Re: sas loop macro

@Jack 1078. Please mark the answer as correct if you have your answer.

Ask a Question
Discussion stats
  • 9 replies
  • 406 views
  • 1 like
  • 7 in conversation