BookmarkSubscribeRSS Feed
talaln
Calcite | Level 5

Hi,

I'm trying to create a table like this:

Untitled.png

 

From this output:

Screenshot_10-5-2024_135831_odamid-apse1.oda.sas.com.jpeg

 

I only want to keep the values where both variable have a value of 1.

The above output was created using the following code:

Proc surveyfreq data=work.ocd;
table dsm_OCD*(Contamination_OC Harming_OC Ordering_OC Hoarding_OC Sex_rel_mor_OC Any_OC One_OC Two_OC Three_OC Four_OC Five_OC)/nowt;
weight finalp2wt;
run;
1 REPLY 1
ballardw
Super User

You use ODS OUTPUT to create data sets containing the results shown in the results.

Then you manipulate the data set for custom reports and use another report procedure like Proc Print, Report or Tabulate to show the results.

 

The bit that you need is to know the name of the object(s) created by your code. That is accomplished by placing ODS Trace statements around the procedure:

ODS Trace on;

<procedure creating output>

ods trace off;

The Log will show something like:

Output Added:
-------------
Name:       Summary
Label:      Data Summary
Template:   Stat.SurveyFreq.Summary
Path:       Surveyfreq.Summary
-------------

Output Added:
-------------
Name:       CrossTabs
Label:      CrossTabulation Table
Template:   Stat.SurveyFreq.CrossTabFreqs
Path:       Surveyfreq.Table1.CrossTabs
-------------


The piece you need is the NAME. These generally appear in the order of the results.

So once you know the name of the object(s) you want then you add them to ODS output in the proc code such as:

Proc surveyfreq data=work.ocd;
   table dsm_OCD*(Contamination_OC Harming_OC Ordering_OC Hoarding_OC         
           Sex_rel_mor_OC Any_OC One_OC Two_OC Three_OC Four_OC   
           Five_OC)/nowt;
    weight finalp2wt;
   ods output crosstabs=mydataset;
run;

This creates a data set name Mydataset with all of the crosstab results. If you have tests they would have results in different objects.

Since I don't have your data  I can't see what you might mean by "both variables have a value of 1".

The output data set will have a variable TABLE that has the variables used to create the given observation.  The values of the Variables will be there plus another variable named F_<your variable> that contains the formatted value of the variable in text. The variable Frequency has the N value, Percent the % and StdErr.

Note that the total values appear so check the Formatted value of the variable for the word Total to identify such.

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1 reply
  • 459 views
  • 0 likes
  • 2 in conversation