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

After sorting the rows, I want to PRINT the top 5 rows only (the top five highest values for FacilityCountry).  I have tried to use (OBS=5) in the PROC PRINT date= statement, but it does not work.  Looking for ideas. 

DATA MIS543.TOYS2;
SET MIS543.TOYS;
KEEP FacilityCountry Sales;
RUN;

PROC REPORT DATA=MIS543.TOYS2 OUT=MIS543.TOYSTABLE;
column FacilityCountry Sales;
define FacilityCountry / "Country" group order=data;
define Sales / "Sales" sum;
format Sales DOLLAR14.;
RUN;

PROC SORT DATA=MIS543.TOYSTABLE;
BY descending Sales;
RUN;

PROC PRINT DATA=MIS543.TOYSTABLE LABEL NOOBS style(header obsheader)=[fontsize=4 color= darkgreen backgroundcolor=lightcyan];
VAR FacilityCountry / style(data)=[fontsize=3 fontweight=bold color=DARKGREEN];
VAR Sales / style(data)=[fontsize=3 fontweight=bold color=DARKGREEN];
title c=darkgreen bold h=5 "Top Five Countries with the Most Sales";
RUN;
TITLE;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Use OBS=5 as a SAS dataset option.

PROC PRINT DATA=MIS543.TOYSTABLE(obs=5) ....

View solution in original post

4 REPLIES 4
Patrick
Opal | Level 21

Use OBS=5 as a SAS dataset option.

PROC PRINT DATA=MIS543.TOYSTABLE(obs=5) ....
tmccombs27
Calcite | Level 5

I guess I had to be exact on where to place the code (directly after the data= file with no space.

Patrick
Opal | Level 21

Spaces wouldn't be an issue. The important bit is that it's within brackets for it to be syntax for a SAS dataset option. Without the brackets SAS will interpret it as an option for Proc Print - which doesn't exist to the code will fail.

ballardw
Super User

Doesn't work is awful vague.

Are there errors in the log?: Post the code and log in a code box opened with the "</>" to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the "</>" icon or attached as text to show exactly what you have and that we can test code against.

 

Since OBS= has been for a very long time one strongly suspects the attempt you actually made was syntactically incorrect but you haven't shown any code with that option to allow pointing out exactly where.

 

Note that there really isn't any reason to create that subset data set of MIS543.Toys2 for input into Proc Report. Report will only use the variables the reference.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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