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

   

                                                                                                                                                          Total54100.000    I am only interested in

I am only interested in the total statistics in the output below. Is there something I should include in the table statement in proc surveyfreq procedure to give me only the totals?

Thanks

 

 

Table of Edu_level by SEX

Controlling for AH_LOCAL_CODE=Z2

AHS_Edu_level

CHAS_SEX

Frequency

Percent

Std Err of Percent

95% Confidence Limits for Percent

CV for Percent

1

1

1

2.6267

2.6343

0.0000

7.7907

1.0029

 

2

11

31.8726

10.4146

11.4571

52.2882

0.3268

 

Total

12

34.4993

10.6584

13.6058

55.3929

0.3089

2

1

3

14.2768

7.9889

0.0000

29.9374

0.5596

 

2

8

31.6395

12.4148

7.3028

55.9762

0.3924

 

Total

11

45.9163

12.2465

21.9096

69.9231

0.2667

3

1

1

2.6267

2.6343

0.0000

7.7907

1.0029

 

2

3

16.1912

9.0225

0.0000

33.8780

0.5572

 

Total

4

18.8179

9.2694

0.6472

36.9887

0.4926

4

1

0

.

.

.

.

.

 

2

1

0.7664

0.7827

0.0000

2.3006

1.0213

 

Total

1

0.7664

0.7827

0.0000

2.3006

1.0213

Total

1

5

19.5303

8.6562

2.5617

36.4989

0.4432

 

2

23

80.4697

8.6562

63.5011

97.4383

0.1076

 

Total

28

100.000

 

 

 

 
1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ
proc surveyfreq data=sashelp.cars;
table type*origin*drivetrain/ CL chisq CV nowt;
weight mpg_city;
ods output CrossTabs=PTable;
run;

proc print data=PTable;
where F_Origin="Total";
run;

Try this cde, which uses the sashelp.cars data set.  You should see "Total" under the F_Origin column.

 

What version of SAS are you running? Submit this statement and send the log:

%put SYSVLONG = &SYSVLONG;

View solution in original post

15 REPLIES 15
Rick_SAS
SAS Super FREQ

You can use ODS OUPUT to write the table to a data set and then use PROC PRINT with a WHERE clause to display only the rows you want.

 

After you write the table to a data set, look at the variables. In your case, there will be a variable named F_AHS_Edu_level that contains the value "Total". The PROC PRINT statement will look something like this:

 

proc print data=CrossTab;
where F_AHS_Edu_level="Total";
var F: Frequency Percent StdErr <other vars here>;
run;

 

 

Lordy
Obsidian | Level 7

Thank you Rick. I run it but it is still not given only the total. Below is the output the code produced. They are the same if you compare it to the previous one i posted. Totals are displayed at every third row.

Obs

Frequency

Percent

StdErr

LowerCL

UpperCL

CV

1

7

24.9

9.7

5.8

44.0

0.3908

2

15

16.7

4.8

7.4

26.1

0.2836

3

22

41.7

9.3

23.5

59.9

0.2227

4

10

29.8

8.7

12.7

46.8

0.2922

5

11

15.6

5.5

4.8

26.3

0.3521

6

21

45.3

9.1

27.5

63.1

0.2004

7

1

3.0

3.0

0.0

8.9

0.9864

8

5

4.6

2.3

0.1

9.2

0.4965

9

6

7.7

3.8

0.3

15.0

0.4884

10

1

2.4

2.4

0.0

7.1

0.9928

11

4

2.9

1.8

0.0

6.4

0.6080

12

5

5.3

3.0

0.0

11.1

0.5580

Lordy
Obsidian | Level 7

wrong output!!

I will post the right one in abit.

Lordy
Obsidian | Level 7

Original output:

Table of Edu_level by SEX

Controlling for AH_LOCAL_CODE=Z1

AHS_Edu_level

CHAS_SEX

Frequency

Percent

Std Err of Percent

95% Confidence Limits for Percent

CV for Percent

1

1

7

24.9168

9.7378

5.8280

44.0057

0.3908

 

2

15

16.7494

4.7506

7.4368

26.0619

0.2836

 

Total

22

41.6662

9.2808

23.4732

59.8592

0.2227

2

1

10

29.7553

8.6937

12.7132

46.7974

0.2922

 

2

11

15.5799

5.4864

4.8251

26.3348

0.3521

 

Total

21

45.3352

9.0834

27.5292

63.1413

0.2004

3

1

1

3.0356

2.9943

0.0000

8.9054

0.9864

 

2

5

4.6445

2.3062

0.1237

9.1654

0.4965

 

Total

6

7.6802

3.7506

0.3279

15.0325

0.4884

4

1

1

2.3974

2.3803

0.0000

7.0634

0.9928

 

2

4

2.9210

1.7758

0.0000

6.4021

0.6080

 

Total

5

5.3184

2.9677

0.0000

11.1360

0.5580

Total

1

19

60.1052

8.0924

44.2418

75.9686

0.1346

 

2

35

39.8948

8.0924

24.0314

55.7582

0.2028

 

Total

54

100.000

 

 

 

 

 

Modified output:

proc print data=PTable;

where Edu_level;

var frequency percent stderr lowerCL upperCL CV;

format percent 8.1

stderr 8.1

LowerCL 8.1

UpperCl 8.1;

run;

Obs

Frequency

Percent

StdErr

LowerCL

UpperCL

CV

1

7

24.9

9.7

5.8

44.0

0.3908

2

15

16.7

4.8

7.4

26.1

0.2836

3

22

41.7

9.3

23.5

59.9

0.2227

4

10

29.8

8.7

12.7

46.8

0.2922

5

11

15.6

5.5

4.8

26.3

0.3521

6

21

45.3

9.1

27.5

63.1

0.2004

7

1

3.0

3.0

0.0

8.9

0.9864

8

5

4.6

2.3

0.1

9.2

0.4965

9

6

7.7

3.8

0.3

15.0

0.4884

10

1

2.4

2.4

0.0

7.1

0.9928

11

4

2.9

1.8

0.0

6.4

0.6080

12

5

5.3

3.0

0.0

11.1

0.5580

 

It is still showing totals on the third rows of the second table. Is there another way I get only the totals

Rick_SAS
SAS Super FREQ
Sorry. Since you didn't post your program, I had to guess at the name of your variables. Look at the PTable data and find the column that has the value "Total" in it. Then modify the WHERE clause to include = "Total", like this:
where F_Edu_level = "Total";
Lordy
Obsidian | Level 7

Sorry about that. This is the code I used

ods trace on;

proc surveyfreq data=data6;

table AH_LOCAL_CODE*Edu_level*SEX/ CL chisq CV nowt;

weight AH_weight;

ods output CrossTabs=PTable;

run;

proc print data=PTable;

where F_Edu_level="Total";

var frequency percent stderr lowerCL upperCL CV;

format percent 8.1

stderr 8.1

LowerCL 8.1

UpperCl 8.1;

run;

Reeza
Super User

Post the output from proc print including all the variables please. 

 

Your most likely not applying the filter correctly, ie your where statement.

Rick_SAS
SAS Super FREQ
proc surveyfreq data=sashelp.cars;
table type*origin*drivetrain/ CL chisq CV nowt;
weight mpg_city;
ods output CrossTabs=PTable;
run;

proc print data=PTable;
where F_Origin="Total";
run;

Try this cde, which uses the sashelp.cars data set.  You should see "Total" under the F_Origin column.

 

What version of SAS are you running? Submit this statement and send the log:

%put SYSVLONG = &SYSVLONG;

Lordy
Obsidian | Level 7

Rick: It worked when i used the sas help dataset.

However, it failed to produce the same output for my data. I am using SAS 9.4

 

Below is the log infor

Output Added:

-------------

Name: CrossTabs

Label: CrossTabulation Table

Template: Stat.SurveyFreq.CrossTabFreqs

Path: Surveyfreq.Table132of1.CrossTabs

-------------

NOTE: The data set WORK.PTABLE has 1056 observations and 12 variables.

NOTE: PROCEDURE SURVEYFREQ used (Total process time):

real time 1.74 seconds

cpu time 0.81 seconds

 

1939 proc print data=PTable;

1940 where F_AHS_Edu_level="Total";

1941 run;

NOTE: No observations were selected from data set WORK.PTABLE.

NOTE: There were 0 observations read from the data set WORK.PTABLE.

WHERE F_AHS_Edu_level='Total';

NOTE: PROCEDURE PRINT used (Total process time):

real time 0.02 seconds

cpu time 0.01 seconds

 

Lordy
Obsidian | Level 7

I am thinking it has something to do with SAS 9.4

 

Thanks very much Rick. You are awesome!!

Rick_SAS
SAS Super FREQ

Run the following procedure and post the results.

 

proc freq data=PTable;

tables _CHAR_;

run;

Lordy
Obsidian | Level 7

Hi Rick, the output is shown below

 

proc surveyfreq data=data6;

table AH_LOCAL_CODE*AHS_Edu_level*CHAS_SEX/ CL chisq CV nowt;

weight AH_weight;

ods output CrossTabs=PTable;

run;

proc freq data=PTable;

tables _CHAR_;

run;

 

 

 

AHS_Edu_level

F_AHS_Edu_level

Frequency

Percent

Cumulative Frequency

Cumulative Percent

1

396

20.00

396

20.00

2

396

20.00

792

40.00

3

396

20.00

1188

60.00

4

396

20.00

1584

80.00

Total

396

20.00

1980

100.00

 

CHAS_SEX

F_CHAS_SEX

Frequency

Percent

Cumulative Frequency

Cumulative Percent

1

660

33.33

660

33.33

2

660

33.33

1320

66.67

Total

660

33.33

1980

100.00

 

 

_SkipLine

Frequency

Percent

Cumulative Frequency

Cumulative Percent

-

528

44.44

528

44.44

1

660

55.56

1188

100.00

Frequency Missing = 792

Rick_SAS
SAS Super FREQ
OK, so
where F_AHS_Edu_level="Total";
should work.
Lordy
Obsidian | Level 7

Rick: It does not produce the proc print for my data. I will past the log message below too.

Thanks!

 

proc surveyfreq data=data6;

table AH_LOCAL_CODE*AHS_Edu_level*CHAS_SEX/ CL chisq CV nowt;

weight AH_weight;

ods output CrossTabs=PTable;

run;

proc print data=PTable;

where F_AHS_Edu_level="Total";

run;

 

 

Output Added:

-------------

Name: CrossTabs

Label: CrossTabulation Table

Template: Stat.SurveyFreq.CrossTabFreqs

Path: Surveyfreq.Table132of1.CrossTabs

-------------

NOTE: The data set WORK.PTABLE has 1980 observations and 13 variables.

NOTE: PROCEDURE SURVEYFREQ used (Total process time):

real time 1.17 seconds

cpu time 1.20 seconds

 

1136

1137 proc print data=PTable;

1138 where F_AHS_Edu_level="Total";

1139 run;

NOTE: No observations were selected from data set WORK.PTABLE.

NOTE: There were 0 observations read from the data set WORK.PTABLE.

WHERE F_AHS_Edu_level='Total';

NOTE: PROCEDURE PRINT used (Total process time):

real time 0.00 seconds

cpu time 0.01 seconds

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 15 replies
  • 2773 views
  • 3 likes
  • 3 in conversation