Dear fellow community,
I am running a simple Proc Freq
data example1;
input x y $ z;
cards;
6 A 60
6 A 70
2 A 100
2 B 10
3 B 67
2 C 81
3 C 63
5 C 55
;
run;
proc freq data = example1;
tables y * x / norow nocol nopercent out = test;
run;
The output dataset ‘test’ looks like below:
y | x | Frequency | Percent of |
Count | Total Frequency | ||
A | 2 | 1 | 12.5 |
A | 6 | 2 | 25 |
B | 2 | 1 | 12.5 |
B | 3 | 1 | 12.5 |
C | 2 | 1 | 12.5 |
C | 3 | 1 | 12.5 |
C | 5 | 1 | 12.5 |
But I really want my test dataset looks exactly as it appears in the result view window as below, is there any simple way to do this without going through proc transpose
|
|
Thanks as always!
I use excel ods below
ods excel file='C:\test.xlsx' options(sheet_name="test");
proc print data=test NOOBS label
style(header)={font_face="Calibri" font_size=8pt}
style(data)={font_face="Calibri" font_size=8pt};
run;
ods excel close;
the output looks as this:
y | x | Frequency Count | Percent of Total Frequency |
A | 2 | 1 | 12.5 |
A | 6 | 2 | 25.0 |
B | 2 | 1 | 12.5 |
B | 3 | 1 | 12.5 |
C | 2 | 1 | 12.5 |
C | 3 | 1 | 12.5 |
C | 5 | 1 | 12.5 |
but I want the dataset looks as
SAS Output
Table of y by xy x2 3 5 6 TotalABCTotal
|
Table of y by x | ||||||||||
y | x | |||||||||
2 | 3 | 5 | 6 | Total | ||||||
A |
|
|
|
|
| |||||
B |
|
|
|
|
| |||||
C |
|
|
|
|
| |||||
Total |
|
|
|
|
|
I got it, thanks @Reeza
The FREQ Procedure | |||||
Table of y by x | |||||
y | x | ||||
Frequency | 2 | 3 | 5 | 6 | Total |
A | 1 | 0 | 0 | 2 | 3 |
B | 1 | 1 | 0 | 0 | 2 |
C | 1 | 1 | 1 | 0 | 3 |
Total | 3 | 2 | 1 | 2 | 8 |
is there a way to get ride of the top for rows, because I need this output as dataset to merge with another dataset
If you need it as a data set then you're better off saving the output and merging it that way. You won't be able to merge in the excel file and you can't easily modify the structure of the PROC FREQ output. You can switch to PROC TABULATE which gives you more control when going straight to Excel.
@zimcom wrote:
I got it, thanks @Reeza
The FREQ Procedure Table of y by x y x Frequency 2 3 5 6 Total A 1 0 0 2 3 B 1 1 0 0 2 C 1 1 1 0 3 Total 3 2 1 2 8
is there a way to get ride of the top for rows, because I need this output as dataset to merge with another dataset
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.