BookmarkSubscribeRSS Feed
HauteDoc
New User | Level 1

Hello.

 

I am new to SAS. I am learning to write efficient code.

 

How do I take my dataset and have it output based on at least three different variables (sex, county and age categories) over a period of time. Not sure if I need to add a merge step

 

ods excel file="NoName2024.xlsx";
 
proc freq data=births;
title 'Dataset, 2018-2023';
    table YOB*age_cat /norow nocol nopercent;
   table  sex*age_cat/norow nocol nopercent;
   table  county*age_cat/norow nocol nopercent;
 
  run;

 

2 REPLIES 2
ballardw
Super User

Are you asking how to create data sets?

Or to have the output displayed differently?

 

 

If you want to create a single data set with the output of multiple Tables statements in PROC FREQ you have two choices:

Old school: Use an out= option on each table statement to create an output data set for each (only one data set per table statement). Then combine them. Whether a Merge or Append would be the better option would depend on what you expected.

 

If ALL of the tables are crosstabs you can use ODS OUTPUT.

An example you should be able to run and examine the output data set mycrosstabdataset.

proc freq data=sashelp.cars;
  ods output crosstabfreqs=mycrosstabdataset;
  tables make*origin;
  tables make*cylinders;
  tables make*type;
run;

The data set has a lot of information because of different variables and table requests used.

Note the above could be created with a table statement like

table make *(origin cylinders type);

If it is to display differently then perhaps a different procedure.

proc tabulate data=sashelp.cars;
   class make origin cylinders type;
   table make,
         (origin cylinders type)*n='Count';
run;
Tom
Super User Tom
Super User

In what way to you want the output to be different than the default PROC FREQ output?

 

Note:  You title talks about creating a DATASET, but your posted code is instead using an existing dataset to make a REPORT.  Which of the two different topics to you need help with?

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!

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.

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
  • 2 replies
  • 134 views
  • 0 likes
  • 3 in conversation