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

Hi, 

 

I need to extract one or two sub-column form the proc freq results involving. if i use list in the code, it doesnot show the 'total' column values. so couldnot opt that too. 

From the attached image, i would need the values of Cylinders with (4.6.8 and total) column values.

Code:

proc freq data=sashelp.cars;

tables make*cylinders / nopercent nocol;

run;

 

 

I have masked the percentage from display. But also, it will be helpful if one could teach me to take the percentage values to separate column values as dataset?

Do pls teach.!

TIA.

 


help topic.png
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

It is good for SQL.



proc sql;
select make,cylinders,count(*) as freq,
count(*)/(select count(*) from sashelp.cars where make=a.make) as per,
(select count(*) from sashelp.cars where make=a.make) as total
from sashelp.cars as a
 where cylinders in ( 4 6 8)
  group by make,cylinders;
run;

View solution in original post

8 REPLIES 8
Reeza
Super User

Please detail what you want as your output. Is this supposed to be a dataset or an output like PROC FREQ?

 


@sooryavasudevan wrote:

if i use list in the code, it doesnot show the 'total' column values. so couldnot opt that too. 

 

 

I have masked the percentage from display. But also, it will be helpful if one could teach me to take the percentage values to separate column values as dataset?

 

 


I don't know what the first sentence means. The second portion, I think you want to include percentage as output?

Also, please refer to the documentation, there are examples that highlight several things you may be interested in:

http://support.sas.com/documentation/cdl/en/procstat/66703/HTML/default/viewer.htm#procstat_freq_exa...

sooryavasudevan
Calcite | Level 5

Hi, 

So, i want my output  as a dataset. Output 3.1.2: Crosstabulation Table click on the link and go the table. 

Lets consider that as my output. then i want my dataset to be in the attached format. 

and i need a code solution for that. Couldnot extract specifically.

Shmuel
Garnet | Level 18

Is this what you are looking for ?

 

proc freq data=sashelp.cars(where=(cylinders in (4 6 8)));

tables make*cylinders / nopercent nocol;

output out = want;

run;

 

If not - where is the problem ?

sooryavasudevan
Calcite | Level 5

Hi,

Ok, so it gave me the output but still in a list format. my desired result are categorical format. PFA

like a tabular form as i given below.

Make | 4 | 6 | 8 | Total | Percent.

 

I know proc freq may not be proper solution. Still couldnot separate the sub-category values and take as output.

Reeza
Super User

Unfortunately none of the procedures will generate a data set in that format. Use a proc transpose to get the format you want. 

Ksharp
Super User

It is good for SQL.



proc sql;
select make,cylinders,count(*) as freq,
count(*)/(select count(*) from sashelp.cars where make=a.make) as per,
(select count(*) from sashelp.cars where make=a.make) as total
from sashelp.cars as a
 where cylinders in ( 4 6 8)
  group by make,cylinders;
run;

sooryavasudevan
Calcite | Level 5

Thanks much 🙂

That helped. Just made little changes to get percentage values.

Shmuel
Garnet | Level 18

By selecting specific cylinders your total will be different from total before selection.

 

So, either you want:

      

proc freq data=sashelp.cars(where=(cylinders in (4 6 8)));

tables make*cylinders / nopercent nocol;

run;

 

or:

proc freq data=sashelp.cars;

output out=my_freq((where=(cylinders in (4 6 8)));

tables make*cylinders / nopercent nocol;

run;

 

Try both and look at results. Chosse whatever fits your expectations.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 8 replies
  • 2746 views
  • 0 likes
  • 4 in conversation