DATA Step, Macro, Functions and more

Please do some help on this,,...

Reply
Contributor
Posts: 22

Please do some help on this,,...

i want to find only aaa from data set..

id  info0 info1 info2 info3 info4 info5 info6

11 aaa  aaa  aaa  aaa  aaa  aaa  aaa

12 aaa  aaa  aaa  aaa  aaa  aaa  aaa

13 bb   bb    aaa  bb     aaa  aaa  aaa

14 bb   bb    aaa  bb     aaa  aaa  aaa

15 bb   aa    aaa  bb     aaa  aaa  aaa




only contains



data a:

11 aaa  aaa  aaa  aaa  aaa  aaa  aaa

12 aaa  aaa  aaa  aaa  aaa  aaa  aaa


data b:

13 bb   bb    aaa  bb     aaa  aaa  aaa

14 bb   bb    aaa  bb     aaa  aaa  aaa

15 bb   aa    aaa  bb     aaa  aaa  aaa






Super User
Posts: 10,500

Re: Please do some help on this,,...

data a b;

     set have;

     if  info0='aaa' and info1='aaa' and  info2='aaa' and  info3='aaa' and  info4='aaa' and  info5='aaa' and  info6='aaa'

          then output a;

     else output b;

run;

Each of your comparisons needs to be appropriate for data type. I put the quotes because aaa would normally be text. If your actual values are numeric then you won't need quotes. If ALL of the values are numeric there might be some shorter code comparisons such as:

if info0=a and max(of info0-info6) = min(of info0-info6) then output a;

Super User
Posts: 5,082

Re: Please do some help on this,,...

very similar:

data a b;

   set have;

   if info0=info1=info2=info3=info4=info5=info6='aaa' then output a;

   else output b;

run;


Respected Advisor
Posts: 3,124

Re: Please do some help on this,,...

Another way, if not using Array:

data have;

     input (id  info0 info1 info2 info3 info4 info5 info6) (:$10.);

     cards;

11 aaa  aaa aaa  aaa  aaa aaa  aaa

12 aaa  aaa aaa  aaa  aaa aaa  aaa

13 bb   bb aaa  bb     aaa aaa  aaa

14 bb   bb aaa  bb     aaa aaa  aaa

15 bb   aa aaa  bb     aaa aaa  aaa

;

data a b;

     set have;

     if catx(',',of infoSmiley Happy = cats('aaa',repeat(',aaa',5)) then

           output a;

     else output b;

run;

Contributor
Posts: 22

Re: Please do some help on this,,...

Hi All,

I want to do it through do loop or arrays..

I have so many variables like nfo ,ifo1 ...info200 and so on

Please help like that only if possible..

Super User
Posts: 10,500

Re: Please do some help on this,,...

If all of the variables are numeric then

if info0=<value> and max(of info0-info200) = min(of info0-info200) then output a;

Array isn't necessary unless you are going to do something else with those variables.

Super User
Posts: 5,082

Re: Please do some help on this,,...

If you are determined to use arrays, here is a method:

data a b;

   set have;

   array inf {201} info0-info200;

   decision = 'A';

   do _i_=1 to 201 until (decision='B');

      if inf{_i_} ne 'aaa' then decision='B';

   end;

   if decision='A' then output a;

   else output b;

   drop decision;

run;

Good luck.

Contributor
Posts: 22

Re: Please do some help on this,,...

Thank you all..I will try these methods and let see if we are good to go

Ask a Question
Discussion stats
  • 7 replies
  • 306 views
  • 0 likes
  • 4 in conversation