BookmarkSubscribeRSS Feed
raveena
Obsidian | Level 7

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..

8 REPLIES 8
Cynthia_sas
SAS Super FREQ

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

raveena
Obsidian | Level 7

Hi Cynthia,

I want to see the results as a SAS dataset.

Thanks

Cynthia_sas
SAS Super FREQ

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

raveena
Obsidian | Level 7

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;

art297
Opal | Level 21

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;                                                                     

Howles
Quartz | Level 8

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..

rtritz
Calcite | Level 5

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

Ksharp
Super User

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1047 views
  • 0 likes
  • 6 in conversation