BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
zimcom
Pyrite | Level 9

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

 

Frequency

Table of y by x

y

x

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

 

 Thanks as always!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Nope, but if you're planning to export this, you could push it directly to Excel using ODS EXCEL.

View solution in original post

6 REPLIES 6
Reeza
Super User
Nope, but if you're planning to export this, you could push it directly to Excel using ODS EXCEL.
zimcom
Pyrite | Level 9

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:

yxFrequency
Count
Percent of
Total
Frequency
A2112.5
A6225.0
B2112.5
B3112.5
C2112.5
C3112.5
C5112.5

 

but I want the dataset looks as 

SAS Output

Table of y by xy x2 3 5 6 TotalABCTotal
1
0
0
2
3
1
1
0
0
2
1
1
1
0
3
3
2
1
2
8
zimcom
Pyrite | Level 9

Table of y by x

y

x

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

Reeza
Super User
You put the PROC FREQ in between the ODS statements, not PROC PRINT.
zimcom
Pyrite | Level 9

I got it, thanks @Reeza

 

The FREQ Procedure
      
Table of y by x
yx
Frequency2356Total
A10023
B11002
C11103
Total32128

 

is there a way to get ride of the top for rows, because I need this output as dataset to merge with another dataset 

Reeza
Super User

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 


 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1746 views
  • 0 likes
  • 2 in conversation