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
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;
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?
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!
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.