SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Proq Freq help please

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 13
Accepted Solution

Proq Freq help please

Evening,

 

current code 

proc import datafile="/home/kcmitche/Basketball Data.xlsx"
out=BB dbms=xlsx replace;
run;

proc freq data=BB;
tables team_name*event_desc_id / crosslist Missing nocum nopercent;
run;

 

 

Question:

When doing a cross tabulation how can i tell SAS to only count how many times a certain event happened in the (even_desc_id)?

I want to count how many times a specific variable happens rather than all of them.

 

 

 

2nd question more advanced.

Is there a way to count how many times something happen (see above) based on what the row below in the data says?

 

thank you


Accepted Solutions
Solution
‎03-20-2017 01:14 PM
Super User
Posts: 6,963

Re: Proq Freq help please


kcmitche wrote:

I'm trying to create a table that will show all the team_names.

then show how many Offensive rebounds they had (listed as 'O') in event_desc_id

that happened directly before a 2FGA or TO

 

Does that make any sense?

 

Essentially I need to figure out how many time a team had an offensive rebound that was directly followed by a certain event.  (The certain event can change) and I'd like to give percentages.

 


data inter;
set have;
if event_desc_id in ('2FGA','TO') and lag(event_desc_id) = 'O'
then output;
run;

proc freq data=inter;
table team_name;
run;

Completely untested, for lack of data.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Posts: 6,963

Re: Proq Freq help please

Use the macro provided in https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... to post an example of your dataset BB in datastep form, and an example what your expected output from proc freq should be.

Do NOT post the Excel file, as it is useless (security, firewalls) in most cases.

 

A variable "happens" in every observation, so I guess you meant how often certain values appear. This is what proc freq does.

 

For your second question, the lag() function might be the answer. But we can help more with example data.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 13

Re: Proq Freq help please

I can't follow and understand how to create the data (from the link you provided)

I'm sorry I'm not as skilled in SAS as I'd like to be.

 

Screenshot of DATA

 

Maybe this screenshot will help with my data since you don't have to download anything.

Super User
Posts: 10,538

Re: Proq Freq help please

And what would the desired result from your posted example "data" be?

Occasional Contributor
Posts: 13

Re: Proq Freq help please

I'm trying to create a table that will show all the team_names.

then show how many Offensive rebounds they had (listed as 'O') in event_desc_id

that happened directly before a 2FGA or TO

 

Does that make any sense?

 

Essentially I need to figure out how many time a team had an offensive rebound that was directly followed by a certain event.  (The certain event can change) and I'd like to give percentages.

 

Solution
‎03-20-2017 01:14 PM
Super User
Posts: 6,963

Re: Proq Freq help please


kcmitche wrote:

I'm trying to create a table that will show all the team_names.

then show how many Offensive rebounds they had (listed as 'O') in event_desc_id

that happened directly before a 2FGA or TO

 

Does that make any sense?

 

Essentially I need to figure out how many time a team had an offensive rebound that was directly followed by a certain event.  (The certain event can change) and I'd like to give percentages.

 


data inter;
set have;
if event_desc_id in ('2FGA','TO') and lag(event_desc_id) = 'O'
then output;
run;

proc freq data=inter;
table team_name;
run;

Completely untested, for lack of data.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 6,963

Re: Proq Freq help please


kcmitche wrote:

I can't follow and understand how to create the data (from the link you provided)

I'm sorry I'm not as skilled in SAS as I'd like to be.


 

Maybe this screenshot will help with my data since you don't have to download anything.


It's not rocket science, just very basic Base SAS usage. Before embarking on anything more complicated with SAS, you should already have developed the necessary SAS skills. Besides, the whole thing is very well documented, so even very novice users can handle it. That is the express purpose of the macro, it is designed to assist newcomers here in providing sample data for their questions.

- download the .zip

- unpack the .sas contained within

- open in EG or Studio or SAS DMS editor (or open with any text editor and copy/paste from there into SAS)

- run it. The macro will be compiled for your current SAS session

Now you can use the macro to convert your dataset, as is described in the linked page.

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 230 views
  • 0 likes
  • 3 in conversation