BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Kirito1
Quartz | Level 8

Can someone guide me how can I achieve the desired result.

I was working on a Code as below:

proc freq data=final;
    tables EMP_CODE*DATE_OF_APPROVAL/nopercent nocum norow nocol;
run;

What should I do to get the below exact result as a table output?

Kirito1_0-1673410861863.png

When I am using the code below

proc freq data=final;
tables EMP_CODE*DATE_OF_APPROVAL/nocum norow nocol nopercent out=table_out_result;
run;

The result is not like the result of proc freq

 

Kirito1_0-1673412049564.png

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@Kirito1 wrote:

OK, got it My bad I understood you point. But can you help me what is that percent column coming after I am applying proc freq. If you have any idea. Please, enlighten me. Thank you for the contribution in making me understand this.


From the documentation of the OUT= table option:

OUT=SAS-data-set

names an output data set that contains frequency or crosstabulation table counts and percentages. If more than one table request appears in the TABLES statement, the contents of the OUT= data set correspond to the last table request in the TABLES statement. The OUT= data set variable COUNT contains the frequencies and the variable PERCENT contains the percentages.

If you don't want the percent variable then could 1) use the drop= data set option :

proc freq data=sashelp.class;
tables sex*age /nopercent nocum norow nocol out=ds (drop=percent);
run;

Or use a different procedure entirely with some different options. One way using Proc Summary/ Means

proc summary data=sashelp.class nway;
   class sex age;
   output out=ds(drop=_type_ rename=(_freq_=count));
run;

 

 

View solution in original post

7 REPLIES 7
ballardw
Super User

@Kirito1 wrote:

Can someone guide me how can I achieve the desired result.

I was working on a Code as below:

proc freq data=final;
    tables EMP_CODE*DATE_OF_APPROVAL/nopercent nocum norow nocol;
run;

What should I do to get the below exact result as a table output?

Kirito1_0-1673410861863.png

When I am using the code below

proc freq data=final;
tables EMP_CODE*DATE_OF_APPROVAL/nocum norow nocol nopercent out=table_out_result;
run;

The result is not like the result of proc freq

 

Kirito1_0-1673412049564.png

 

 

 


The first thing would be to provide example data of the set Final. Second is define exactly what you mean by table in this context.

There is no way that a DATASET will have multiple rows of header information. Nada. Zip. None. Zilch. You will have one variable name with an optional label per column. No way "Table of anythiing" or a spanning "Date_of_approval" will appear as part of a data set.

 

If you mean that you want variables with names like "01JAN2023" then you are doing stuff that just will add difficulty for most things in the long run because you have to 1) use options to allow non-standard names, 2) would require referencing those names with quotes and n as "01JAN2023"n and 3) have placed data into variable names.

Kirito1
Quartz | Level 8

OK, got it My bad I understood you point. But can you help me what is that percent column coming after I am applying proc freq. If you have any idea. Please, enlighten me. Thank you for the contribution in making me understand this.

ballardw
Super User

@Kirito1 wrote:

OK, got it My bad I understood you point. But can you help me what is that percent column coming after I am applying proc freq. If you have any idea. Please, enlighten me. Thank you for the contribution in making me understand this.


From the documentation of the OUT= table option:

OUT=SAS-data-set

names an output data set that contains frequency or crosstabulation table counts and percentages. If more than one table request appears in the TABLES statement, the contents of the OUT= data set correspond to the last table request in the TABLES statement. The OUT= data set variable COUNT contains the frequencies and the variable PERCENT contains the percentages.

If you don't want the percent variable then could 1) use the drop= data set option :

proc freq data=sashelp.class;
tables sex*age /nopercent nocum norow nocol out=ds (drop=percent);
run;

Or use a different procedure entirely with some different options. One way using Proc Summary/ Means

proc summary data=sashelp.class nway;
   class sex age;
   output out=ds(drop=_type_ rename=(_freq_=count));
run;

 

 

Kirito1
Quartz | Level 8
thanks for the contribution ballardw..............Its working now 🙂
Ksharp
Super User
data have;
 set sashelp.class;
run;

proc sql;
create table temp as
select 1 as id1,sex as sex length=80,
       1 as id2,put(age,best. -l) as age length=80,
       count(*) as n
 from have
  group by sex,age
union all
select 1 as id1,sex,
       2 as id2,'Total',
       count(*) as n
 from have
  group by sex
union all
select 2 as id1,'Total',
       1 as id2,put(age,best. -l),
       count(*) as n
 from have
  group by age
union all
select 2 as id1,'Total',
       2 as id2,'Total',
       count(*) as n
 from have
order by 1,2,3,4
;
quit;
options validvarname=any missing='0';
proc transpose data=temp out=want(drop=_name_);
by sex notsorted;
id age;
var n;
run;

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 7 replies
  • 872 views
  • 4 likes
  • 4 in conversation