BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi Guys,
I need a code to generate the following output...I am including the data set.

Data set:

System Defect

Cardiovascular Atheroscelorosis
Neurology Vertigo
Cardiovascular Myocardialinfaction
Nephrology Renal Failure
Gastroenterology Gastritis
Gastroenterology Jaundice
Gastroenterology Gastritis
Cardiovascular Myocardialinfaction

Output:
Defect Frequency

Cardiovascular
Atheroscelorosis 1
Myocardialinfaction 2
Nephrology
Renal Failure 1
Gastroenterology
Gastritis 1
Jaundice 1
Gastritis 1

Thanks & Regards
Nani
10 REPLIES 10
Rens_SASNL
SAS Employee
Maybe something like this:

data read;
length system_defect $ 200;
input system_defect &;
system=scan(system_defect,1);
defect=left(tranwrd(system_defect,trimn(system),''));
cards;
Cardiovascular Atheroscelorosis
Neurology Vertigo
Cardiovascular Myocardialinfaction
Nephrology Renal Failure
Gastroenterology Gastritis
Gastroenterology Jaundice
Gastroenterology Gastritis
Cardiovascular Myocardialinfaction
;run;
proc sort;
by system defect;
run;
data result;
set read(drop=system_defect);
by system defect;
if first.defect then count=0;
count+1;
run;


Regards,

Rens, SAS NL
advoss
Quartz | Level 8
Change last data step to:
data result;
set read(drop=system_defect);
by system defect;
if first.defect then count=0;
count+1;
if last.defect then output;
run;
Cynthia_sas
SAS Super FREQ
Hi:
Either PROC REPORT or PROC TABULATE will give you a table based on your data.
[pre]
data defects;
length system $20 defect $20;
infile datalines;
input system $ defect $;
return;
datalines;
Cardiovascular Atheroscelorosis
Neurology Vertigo
Cardiovascular Myocardialinfaction
Nephrology Renal Failure
Gastroenterology Gastritis
Gastroenterology Jaundice
Gastroenterology Gastritis
Cardiovascular Myocardialinfaction
;
run;

[/pre]

Then PROC REPORT looks like this in the LISTING window:
[pre]

proc report data=defects nowd;
title 'With Proc Report';
column system defect n;
define system /group;
define defect /group;
run;

The OUTPUT:
With Proc Report

system defect n
Cardiovascular Atheroscelorosis 1
Myocardialinfaction 2
Gastroenterology Gastritis 2
Jaundice 1
Nephrology Renal 1
Neurology Vertigo 1

[/pre]

There are other ways to pretty up the PROC REPORT output, but PROC TABULATE does exactly what you want. And, PROC TABULATE looks like this in the LISTING window:

[pre]
proc tabulate data=defects f=9. noseps
formchar=' ';
title 'With Proc Tabulate';
class system defect;
table system*defect,n='Frequency'/
row=float indent=2 box='Defect'
rts=24;
run;

The OUTPUT:

With Proc Tabulate

Defect Frequency

Cardiovascular
Atheroscelorosis 1
Myocardialinfaction 2
Gastroenterology
Gastritis 2
Jaundice 1
Nephrology
Renal 1
Neurology
Vertigo 1

[/pre]

cynthia
1162
Calcite | Level 5
As Cynthia and others have pointed out, it depends on what you want produced. Here is yet another option (sorry about the look, but I can't seem to produce the nice formatting that others use):

data in;
input (system defect) (:$24.);
cards;
Cardiovascular Atheroscelorosis
Neurology Vertigo
Cardiovascular Myocardialinfaction
Nephrology Renal Failure
Gastroenterology Gastritis
Gastroenterology Jaundice
Gastroenterology Gastritis
Cardiovascular Myocardialinfaction
;
run;

options nocenter;
proc report data=in nowindows;
columns system defect N;
define system / group noprint;
define defect / group;
break after system / skip;
compute before system;
line @3 system $24.;
endcomp;
run;

Output:

defect N
Cardiovascular
Atheroscelorosis 1
Myocardialinfaction 2

Gastroenterology
Gastritis 2
Jaundice 1

Nephrology
Renal 1

Neurology
Vertigo 1
Cynthia_sas
SAS Super FREQ
Hi:
to get the "nice" formatting, use square bracket-pre-square bracket before your code
and
square bracket - /pre-square bracket
after your code

square bracket = [ ]
[-pre-] (without the dashes) and
[-/pre-] (without the dashes)
cynthia
madhu
Calcite | Level 5
Hi Cynthia ,

The code u have posted actually approximately meets my needs.But the problem I have is I need to get the total count(& percentage as xx.x%) of all the defects persystem along with the defects in each system.
Some thing like this...

CardioVascular 3
Atheroscelorosis 1
Myocardialinfaction 2
Neurology 1
Vertigo 1

And further I need to generate the same as a Dataset or a ODS output..

Thanks & Regards
Rajesh
Cynthia_sas
SAS Super FREQ
Hi:
You can get counts and percents from either PROC REPORT or PROC TABULATE using the N and PCTN statistic.

For more help with the syntax of either procedure or the syntax of the program example below or for help creating a dataset from ODS procedure output, your best bet is to contact SAS Technical Support. Also, many companies that do clinical trial reporting ALREADY have procedures and macro programs that they use to generate the kinds of reports that you ask about. So, before you go too far down the road of ANY procedure, you should check with other programmers at your company to determine what validated programs and methods are already in use.

To contact SAS Technical Support, go to http://support.sas.com/ and in the left-hand navigation pane, click on the link entitled "Submit a Problem".

cynthia

Some example code:
[pre]
data defects;
length system $20 defect $20;
infile datalines;
input system $ defect $;
return;
datalines;
Cardiovascular Atheroscelorosis
Neurology Vertigo
Cardiovascular Myocardialinfarction
Nephrology Renal Failure
Gastroenterology Gastritis
Gastroenterology Jaundice
Gastroenterology Gastritis
Cardiovascular Myocardialinfarction
;
run;

proc format;
picture pct low-high='009.99%';
run;

ods html file='c:\temp\pctrept.html' style=sasweb;

proc tabulate data=defects ;
title 'Percents and Counts with PROC TABULATE';
class system defect;
table system=' ' * (all defect=' ' ) all,
n pctn*f=pct. /
box='system and defect';
run;

proc report data=defects nowd
style(summary)=Header;
title 'Percents and Counts with PROC REPORT';
column system defect n pctn;
define system /group
style(column)=Header;
define defect/group
style(column)=Header;
define n/ 'N' f=comma6.;
define pctn / 'PctN' f=percent8.2;
break before system/ summarize;
compute before system;
defect = 'All';
endcomp;
compute after system;
line ' ';
endcomp;
rbreak after /summarize;
compute after;
system = 'All';
defect = 'All';
endcomp;
run;
ods html close;
[/pre]
LawrenceHW
Quartz | Level 8
Another alternative is that you calculate your frequency counts and totals using a summary procedure (FREQ, SQL, MEANS, UNIVARIATE - take your pick - I've seen lots of different methods) and merge the totals and frequencies together. Calculate %age, create a character variable {xx (xxx%)} and use PROC REPORT to print out the xx (xxx%) variables along with labels, headers, footers, etc.

That's pretty much what I do anyway ... mainly because I dislike TABULATE ...
deleted_user
Not applicable
I do have a problem similar to that of Mr.Rajesh.Can anybody help me out?

Regards,
Nani
madhu
Calcite | Level 5
Thanks for the replies guys..

cheers,
rajesh

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Health and Life Sciences Learning

 

Need courses to help you with SAS Life Sciences Analytics Framework, SAS Health Cohort Builder, or other topics? Check out the Health and Life Sciences learning path for all of the offerings.

LEARN MORE

Discussion stats
  • 10 replies
  • 2577 views
  • 0 likes
  • 7 in conversation