SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
sasgorilla
Pyrite | Level 9

I am using SAS 9.4 and have a large data set with various missing data patterns. This is my first time exploring MI in SAS independently, so I ran the below code based on the user guide. 

proc mi nimpute=0 data=a out=patterns;
run;

This produced a missing data patterns table with 57 different patterns.  Is there a way to sort these patterns in the table, such as by frequency or percentage of pattern, or from least to most missing variables?

 

I looked through the user guide and could not find any specific option to do this. Also, it doesn't appear the output data set contains any observations to sort by. 

 

It seems this would be helpful to identify patterns and think through approaches to imputation. 

 

Thanks in advance. 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

You can get almost any output table into a data set though it may look a bit different than the displayed version.

The generic skill is learning to use the ODS Trace to determine the name(s) of the created objects the procedure created. Then use that information to write and ODS OUTPUT statement.

Or look up in the documentation for the procedure for the ODS Table Names shown in the Details tab.

 

Here is an example with Proc freq since I don't have your data.

ods trace on;

proc freq data=sashelp.class nlevels;
  tables sex*age / chisq;
run;

ods trace off;

The LOG will show the created objects such as:

Output Added:
-------------
Name:       NLevels
Template:   Base.Freq.NLevels
Path:       Freq.NLevels
-------------

Output Added:
-------------
Name:       CrossTabFreqs
Label:      Cross-Tabular Freq Table
Template:   Base.Freq.CrossTabFreqs
Path:       Freq.Table1.CrossTabFreqs
-------------

Output Added:
-------------
Name:       ChiSq
Label:      Chi-Square Tests
Template:   Base.Freq.ChiSq
Path:       Freq.Table1.ChiSq
-------------

So if I want to create data sets from the ods output:

proc freq data=sashelp.class nlevels;
  tables sex*age / chisq;
  ods output nlevels=work.nlevelset
             crosstabfreqs= work.mycrosstab
             chisq = work.mychisq
  ;
run;

If you have a very large data set it is likely worth while to use the data set option OBS= to reduce the number of observations used by the procedure to reduce time for the procedure if you are running it only to get the table names.

 

Yes, proc freq will create an output data set for the crosstabs. But the ODS OUTPUT will allow placing multiple tables such as tables statement with : Tables (race age sex origin)*( q1 q2 q3 );

Which would require 12 Tables statements to get the cross tabs for all 12 combinations of the variables requested.Ods output will place them all in one set with an indication of which table each row represents.

 

 

View solution in original post

2 REPLIES 2
ballardw
Super User

You can get almost any output table into a data set though it may look a bit different than the displayed version.

The generic skill is learning to use the ODS Trace to determine the name(s) of the created objects the procedure created. Then use that information to write and ODS OUTPUT statement.

Or look up in the documentation for the procedure for the ODS Table Names shown in the Details tab.

 

Here is an example with Proc freq since I don't have your data.

ods trace on;

proc freq data=sashelp.class nlevels;
  tables sex*age / chisq;
run;

ods trace off;

The LOG will show the created objects such as:

Output Added:
-------------
Name:       NLevels
Template:   Base.Freq.NLevels
Path:       Freq.NLevels
-------------

Output Added:
-------------
Name:       CrossTabFreqs
Label:      Cross-Tabular Freq Table
Template:   Base.Freq.CrossTabFreqs
Path:       Freq.Table1.CrossTabFreqs
-------------

Output Added:
-------------
Name:       ChiSq
Label:      Chi-Square Tests
Template:   Base.Freq.ChiSq
Path:       Freq.Table1.ChiSq
-------------

So if I want to create data sets from the ods output:

proc freq data=sashelp.class nlevels;
  tables sex*age / chisq;
  ods output nlevels=work.nlevelset
             crosstabfreqs= work.mycrosstab
             chisq = work.mychisq
  ;
run;

If you have a very large data set it is likely worth while to use the data set option OBS= to reduce the number of observations used by the procedure to reduce time for the procedure if you are running it only to get the table names.

 

Yes, proc freq will create an output data set for the crosstabs. But the ODS OUTPUT will allow placing multiple tables such as tables statement with : Tables (race age sex origin)*( q1 q2 q3 );

Which would require 12 Tables statements to get the cross tabs for all 12 combinations of the variables requested.Ods output will place them all in one set with an indication of which table each row represents.

 

 

sasgorilla
Pyrite | Level 9

Thank you! I mimicked this and was able to reproduce the table I was after to sort and manipulate otherwise. Very helpful. 

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

Register now!

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
  • 2 replies
  • 493 views
  • 4 likes
  • 2 in conversation