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

Hello,

 

I am new in SAS and having hard time figuring out freq and sort procedures. Please assist me with the following questions:

 

Which industry code has the most records in file Q_COMP_SHORT10_18?  

 

Which State has the most records in file Q_COMP_SHORT10_18?

 

Find the Top100 records with the highest average inventory turnover?

 

I am not sure if the industry code is SIC or TIC ?

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You can run a PROC FREQ and specify that the data is ordered by frequency so that you can easily find the top values. 

 

I would assume SIC is Standard Industry Classification but that's not something someone external can answer with any certainty because we don't know about your data. 

 

Here's an example on how you'd answer which is the more frequent SEX in the data set

proc freq data=sashelp.class order=freq;
table sex;
run;

@FEFE90 wrote:

Hello,

 

I am new in SAS and having hard time figuring out freq and sort procedures. Please assist me with the following questions:

 

Which industry code has the most records in file Q_COMP_SHORT10_18?  

 

Which State has the most records in file Q_COMP_SHORT10_18?

 

Find the Top100 records with the highest average inventory turnover?

 

I am not sure if the industry code is SIC or TIC ?

 

Thank you


 

View solution in original post

9 REPLIES 9
Reeza
Super User

You can run a PROC FREQ and specify that the data is ordered by frequency so that you can easily find the top values. 

 

I would assume SIC is Standard Industry Classification but that's not something someone external can answer with any certainty because we don't know about your data. 

 

Here's an example on how you'd answer which is the more frequent SEX in the data set

proc freq data=sashelp.class order=freq;
table sex;
run;

@FEFE90 wrote:

Hello,

 

I am new in SAS and having hard time figuring out freq and sort procedures. Please assist me with the following questions:

 

Which industry code has the most records in file Q_COMP_SHORT10_18?  

 

Which State has the most records in file Q_COMP_SHORT10_18?

 

Find the Top100 records with the highest average inventory turnover?

 

I am not sure if the industry code is SIC or TIC ?

 

Thank you


 

FEFE90
Calcite | Level 5

Thank you for your response. so we don't have to sort the data before using proc freq ? 

 

Bests

PGStats
Opal | Level 21

Try it! You'll see.

PG
Reeza
Super User

@FEFE90 wrote:

Thank you for your response. so we don't have to sort the data before using proc freq ? 

 

Bests


It depends on the PROC FREQ code. You're only required to sort your data if you're using a BY statement and then the BY statement will be the same between the SORT and FREQ procedure. Given your current question, there's no need for BY group analysis and no need to pre-sort your data. 


The FREQ option will ensure the output is sorted to make it easier to answer your questions. And, as @PGStats mentioned, the best thing about programming is you can always answer these questions yourself by running various options and seeing what happens. 

FEFE90
Calcite | Level 5

Can you please check the last question: Finding the top100 with the highest average inventory turnover? I did this but it gave me wrong answer?

 

data TOP100; set Q_COMP_SHORT10_18;
keep ATQ COGSQ  AVG_INVENTORY_TURNOVER;
AVG_INVENTORY_TURNOVER = COGSQ/ATQ;
run;
 
proc sort data = TOP100;
by descending AVG_INVENTORY_TURNOVER ;
run;
 
data TOP100 ; set Q4;
if _N_<=100;
run;
 
Thank you
FEFE90
Calcite | Level 5

Thank you I changed it to TOP100, but still the answer is wrong.

Kurt_Bremser
Super User

Define "wrong". The word as such tells us exactly NOTHING.

Supply example data so we can run your code against it, and tell us where the result differs from your expectations.

Use a data step with datalines to post example data, see my footnotes.

FEFE90
Calcite | Level 5

I can check the final answer if it's correct or not. But it is not shown the correct code. I will see it thank you

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 9 replies
  • 1041 views
  • 0 likes
  • 4 in conversation