data have;
input a $;
cards;
car
bus
jeep
aeroplane
maruti
run;
want:
a count
car 1
bus 1
other 3
proc sql; create table want as select a, count(*) as count from (select case when a not in ("car","bus") then "other" else a end as a from have) group by a; quit;
But this is the same as simply categorising your data beforehand into the required output:
data have; length a $20; input a $; if a not in ("car","bus") then a="other"; cards; car bus jeep aeroplane maruti ; run;
I have more then 10 records is any other way to do. Thanks for the response.
@rajeshalwayswel wrote:
I have more then 10 records is any other way to do. Thanks for the response.
Why is the number of records a problem?
if a not in ("car","bus") then a="other";
if I use this step so I need to mention all the rest of them in the operators.
@rajeshalwayswel wrote:
if a not in ("car","bus") then a="other";if I use this step so I need to mention all the rest of them in the operators.
So, after having a second look at the data you posted, you need to count the observations beginning with the third one, right?
Try:
data want;
set have end=jobDone;
retain count;
if _n_ < 3 then do;
count = 1;
output;
count = 0;
end;
else do;
count = count + 1;
end;
if jobDone then do;
a = 'other';
output;
end;
run;
Please post test data which describes your problem, I can only work with what you provide.
data have;
input a $;
cards;
car
bus
jeep
aeroplane
maruti
run;
proc format ;
value $fmt
'car'='car'
'bus'='bus'
other='other';
run;
proc freq data=have;
table a /out=want;
format a $fmt.;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.