Hi I have some data that I am using proc summary to tidy up so I can output it as a text file.
I am having some issues, for the text file they want both male and female counts on the same line, however when using proc summary when I use the variable gender in the class statement it separates them.
proc summary data=undup nway;
class gender Class Ethnic ;
var count;
format Ethnic $ethnic.;
output out=undupFinal sum=;
run;
I like the format that proc summary gives me but I would like to be able to have both the male count and female count on the same line. Is there a way to do this with proc summary?
Yes I am familiar with ODS and outputting to PDF and Excel. I inherited this program and the previous coder used proc summary to group and aggregate the data by categories and then output it to a text file.
They didn't need to report different counts for genders at the time so I am not sure proc summary is the best way forward. I am realizing that I need to have one line with counts for the different combinations of gender and ethnicity.
The output needs to be in a certain format, so for example the output would be a number for white females that starts at column 35 and the output for Hispanic men would be a number at column 53 on the text file.
@helloagainoh2 wrote:
Yes I am familiar with ODS and outputting to PDF and Excel. I inherited this program and the previous coder used proc summary to group and aggregate the data by categories and then output it to a text file.
They didn't need to report different counts for genders at the time so I am not sure proc summary is the best way forward. I am realizing that I need to have one line with counts for the different combinations of gender and ethnicity.
The output needs to be in a certain format, so for example the output would be a number for white females that starts at column 35 and the output for Hispanic men would be a number at column 53 on the text file.
It may help to provide the full description of the text file.
When specific columns positions are needed that quite often calls for a Data step to full control and might require transposing the output from Summary before creating the output text file.
@helloagainoh2 wrote:
Yes I am familiar with ODS and outputting to PDF and Excel. I inherited this program and the previous coder used proc summary to group and aggregate the data by categories and then output it to a text file.
They didn't need to report different counts for genders at the time so I am not sure proc summary is the best way forward. I am realizing that I need to have one line with counts for the different combinations of gender and ethnicity.
The output needs to be in a certain format, so for example the output would be a number for white females that starts at column 35 and the output for Hispanic men would be a number at column 53 on the text file.
No need to convert the data before writing the text file.
Say you have a variable GROUP, SEX, RACE and COUNT and the data is sorted by GROUP then you can write all of the values for the same group to the same line. Just use the trailing @ on the PUT statement.
data _null_;
set have;
by group;
file 'myfile.txt';
...
if sex='FEMALE' and RACE='WHITE' then put @35 count @;
...
if last.group then put;
run;
It's not clear why you would want them both on one line, but in general, the idea of converting a long data set (which is what PROC SUMMARY gives you) into a much wider data set where everything is on one line, is generally considered to be poor practice, and makes your coding much more difficult. See Maxim 19, Long beats Wide.
So why do you want this? What are you going to do with this wide and flat data that you can't do with the actual PROC SUMMARY output?
It's for an automated service that reads the text file for verification, they want the data on the text file outputted on certain columns at certain lengths.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.