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

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

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.

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
  • 8 replies
  • 1744 views
  • 0 likes
  • 4 in conversation