How To derive desired sub-column variable to dataset from proc freq result

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

How To derive desired sub-column variable to dataset from proc freq result

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.

 

Attachment

Accepted Solutions
Solution
‎09-21-2016 10:37 PM
Grand Advisor
Posts: 9,567

Re: How To derive desired sub-column variable to dataset from proc freq result


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


All Replies
Grand Advisor
Posts: 17,313

Re: How To derive desired sub-column variable to dataset from proc freq result

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...

New Contributor
Posts: 4

Re: How To derive desired sub-column variable to dataset from proc freq result

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.

Super User
Posts: 1,226

Re: How To derive desired sub-column variable to dataset from proc freq result

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 ?

New Contributor
Posts: 4

Re: How To derive desired sub-column variable to dataset from proc freq result

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.

Grand Advisor
Posts: 17,313

Re: How To derive desired sub-column variable to dataset from proc freq result

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

Solution
‎09-21-2016 10:37 PM
Grand Advisor
Posts: 9,567

Re: How To derive desired sub-column variable to dataset from proc freq result


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;

New Contributor
Posts: 4

Re: How To derive desired sub-column variable to dataset from proc freq result

Thanks much Smiley Happy

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

Super User
Posts: 1,226

Re: How To derive desired sub-column variable to dataset from proc freq result

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.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 923 views
  • 0 likes
  • 4 in conversation