BookmarkSubscribeRSS Feed
jack1078
Calcite | Level 5

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

9 REPLIES 9
MadhuKorni
Quartz | Level 8

Hi Jack,

Can you be somewhat clear about the issue.

You closed the do loop inside the datastep block.

jack1078
Calcite | Level 5

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.

Astounding
PROC Star

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? 

jack1078
Calcite | Level 5

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

Reeza
Super User

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

Tom
Super User Tom
Super User

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;

jack1078
Calcite | Level 5

thank's a lot, tom

you have been very useful

bie bie

ChrisNZ
Tourmaline | Level 20

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 1329 views
  • 1 like
  • 7 in conversation