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.
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;
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:
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.
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 ?
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.
Unfortunately none of the procedures will generate a data set in that format. Use a proc transpose to get the format you want.
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;
Thanks much 🙂
That helped. Just made little changes to get percentage values.
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.
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!
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.