Hi ,
I need a help to get an deisred output as below,
(Need to consider PS1 ,PS2 as PS)
CODE SPECIALTY
PS OBGYN
PS SURG
PS1 OBGYN
PS1 ANES
PS1 NEPH
PS2 OBGYN
PS2 NEPH
OUTPUT SHOULD BE APPEAR AS BELOW,
CODE SPECIALTY OCCURRENCES
PS OBGYN 3
PS SURG 1
PS ANES 1
PS NEPH 2
Thanks in Advance..
Hi:
What code have you tried? How do you want to see the results? As a SAS dataset? As output in the SAS LISTING window? As an HTML output file? As RTF or PDF output? As a CSV file?
There are several different SAS procedures that will produce this type of report. You might need a bit of data manipulation or special user-defined format to take care of the recoding for the CODE variable. The procedure and method you use really depends on what your desired end result is.
cynthia
Hi Cynthia,
I want to see the results as a SAS dataset.
Thanks
Hi:
You did not say what code you had tried.
I can think of PROC REPORT, PROC FREQ, PROC TABULATE, PROC SQL or PROC MEANS or a custom DATA step program, as possible ways to create an output SAS dataset from the data you posted. Most of the procedure methods support an OUT= option to create an output dataset. The DATA step approach would use FIRST.and LAST. BY processing to accumulate an OCCURENCE variable for CODE/SPECIALITY combinations. Many different possibilities...
cynthia
Cynthia,
I tried this below code,
data d;
set specinfoo ;
by pancod spccod;
if first.spccod then occurrences=0;
occurrences+1;
if last.spccod then output;
run;
proc sort data=d out=e;
by pancod occurrences;
run;
data f;
set e;
by pancod;
if last.pancod then output;
run;
How about trying something like:
data need;
set have (rename=(code=code_in));
code=compress(code_in,,'ka');
run;
proc sort data=need;
by code;
run;
ods listing close;
ods output OneWayFreqs=want;
proc freq data=need (keep=code specialty);
tables specialty;
by code;
run;
ods output close;
ods listing;
PROC FREQ is the SAS component designed to count things. It looks like this problem can be solved in one step, using built-in features.
data have ;
input
CODE $ SPECIALTY $ ; cards ;
PS OBGYN
PS SURG
PS1 OBGYN
PS1 ANES
PS1 NEPH
PS2 OBGYN
PS2 NEPH
;
proc freq data=have noprint ;
by code ;
format code $2. ;
tables specialty /
out=want( rename = (count=OCCURRENCES) drop = percent ) ;
run ;
raveena wrote:
Hi ,
I need a help to get an deisred output as below,
(Need to consider PS1 ,PS2 as PS)
CODE SPECIALTY
PS OBGYN
PS SURG
PS1 OBGYN
PS1 ANES
PS1 NEPH
PS2 OBGYN
PS2 NEPH
OUTPUT SHOULD BE APPEAR AS BELOW,
CODE SPECIALTY OCCURRENCES
PS OBGYN 3
PS SURG 1
PS ANES 1
PS NEPH 2
Thanks in Advance..
Hi,
A simple modification to Howles' code should give you the exact ordered output you want.
Just add the order = data option to the proc freq statement and you will get the order you
want for specialty instead of alphabetical order.
Rich
It is another varying version of Howles's code .
data have ; input CODE $ SPECIALTY $ ; cards ; PS OBGYN PS SURG PS1 OBGYN PS1 ANES PS1 NEPH PS2 OBGYN PS2 NEPH ; run; proc freq data=have noprint; format code $2.; tables code*specialty/list out=want(drop=percent) nocum nopercent; run;
Ksharp
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.