BookmarkSubscribeRSS Feed
pankak
Calcite | Level 5

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






7 REPLIES 7
ballardw
Super User

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;

Astounding
PROC Star

very similar:

data a b;

   set have;

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

   else output b;

run;


Haikuo
Onyx | Level 15

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 info:) = cats('aaa',repeat(',aaa',5)) then

           output a;

     else output b;

run;

pankak
Calcite | Level 5

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..

ballardw
Super User

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.

Astounding
PROC Star

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.

pankak
Calcite | Level 5

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

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!

How to Concatenate Values

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.

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
  • 7 replies
  • 971 views
  • 0 likes
  • 4 in conversation