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
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;
very similar:
data a b;
set have;
if info0=info1=info2=info3=info4=info5=info6='aaa' then output a;
else output b;
run;
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;
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..
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.
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.
Thank you all..I will try these methods and let see if we are good to go
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.
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.