Hi Reader,
Here is some new understanding i am exploring, so could you please share the solution?
/*Input data*/
data abc ;
input dsc $ ;
cards;
a
a
c
b
b
b
b
;
run;
/*Output requirement*/
b | c | a | total count |
(n=4) | (n=1) | (n=2) | (n=7) |
data abc ;
input dsc $ ;
cards;
a
a
c
b
b
b
b
;
run;
proc sql;
create table temp as
select dsc, count(dsc) as count, (select count( dsc ) from abc) as total_count
from abc
group by dsc;
quit;
proc transpose data=temp out=want(drop=_:);
by total_count;
var count;
id dsc;
run;
I will prefer this kind of output-
proc sql;
create table temp as
select dsc, cat ("(n","=",count(dsc),")") as count, (select cat ("(n","=",count( dsc ),")") from abc) as total_count
from abc
group by dsc;
quit;
One basic approach:
proc tabulate data=abc; class dsc; table n, dsc all='Total' ; run;
If the output actually requires the ugly-to-me (n= ) that's another story.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.