BookmarkSubscribeRSS Feed
pdhokriya
Pyrite | Level 9

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)

 

4 REPLIES 4
novinosrin
Tourmaline | Level 20

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;
pdhokriya
Pyrite | Level 9

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;

ballardw
Super User

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.

Reeza
Super User
Use PROC FREQ - which is the most basic solution.

PROC FREQ data=abc;
table dsc;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1033 views
  • 3 likes
  • 4 in conversation