BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Banke
Pyrite | Level 9

Hello,

i was asked to print obervations with 5 highest frequencies from a big dataset. i did this to order the frequency in descending order.

 

PROC FREQ DATA = WEEK6.THCICSAMP ORDER = FREQ;
TABLES ADMITTING_DIAG PRINC_DIAG_CODE;
RUN;

but i want to print , so i tried to create a new data set with only my frequencies for the 2 variables, sort by decreasing frequencies and use proc print :

PROC FREQ DATA = WEEK6.THCICSAMP STACKODSOUTPUT NOPRINT;
TABLES ADMITTING_DIAG PRINC_DIAG_CODE /OUT = WEEK6.FREQDIAG;
RUN;

i noticed that the new data set week6.freqdiaq i created has only one of the variable, PRINC_DIAG_CODE. how can i get all my variables out into the new dataset please?

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
You need two TABLES statements ,and combine them later by data step.

PROC FREQ DATA = WEEK6.THCICSAMP NOPRINT;
TABLES ADMITTING_DIAG /OUT = WEEK6.ADMITTING_DIAG ;
TABLES PRINC_DIAG_CODE /OUT = WEEK6.PRINC_DIAG_CODE ;
RUN;

View solution in original post

6 REPLIES 6
Ksharp
Super User
You need two TABLES statements ,and combine them later by data step.

PROC FREQ DATA = WEEK6.THCICSAMP NOPRINT;
TABLES ADMITTING_DIAG /OUT = WEEK6.ADMITTING_DIAG ;
TABLES PRINC_DIAG_CODE /OUT = WEEK6.PRINC_DIAG_CODE ;
RUN;
Banke
Pyrite | Level 9

Thank you so much, I wanted to do it all in one step.

Watts
SAS Employee

You could use ODS.  

PROC FREQ DATA = WEEK6.THCICSAMP ORDER = FREQ;
TABLES ADMITTING_DIAG PRINC_DIAG_CODE;
ods output onewayfreqs=out;
RUN;

 

 

Banke
Pyrite | Level 9

When  I wanted to print out the observations though, I noticed the PRINC_DIAG_CODE variable is blank

 

Olajumoke_0-1633461979747.png

 

Banke
Pyrite | Level 9

the variables in the two dataset i have created have similar names, so if i use merge command in my datastep, one will overwrite the other, do i have to rename the observations? they both have count and percentage of frequency count in common as variable names. do i also have to create a common variable like ID number to merge them ?

thanks

Ksharp
Super User

yes. you need rename it before set them all.

 

proc freq data=sashelp.class noprint ;
table weight/out=weight(rename=(weight=vname));
table age/out=age(rename=(age=vname));
run;

data want;
 set weight age indsname=dsn;
 dsname=dsn;
run;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1670 views
  • 1 like
  • 3 in conversation