BookmarkSubscribeRSS Feed
sasiscool
Obsidian | Level 7

I have a data set of counts of products that I set up in SAS.

 

label         start           fmtname       etc.   freq.

apple       apple           $prodfmt              40

cherry      cherry         $prodfmt               37

pen           pen          $prodfmt                32

 

 

I have the type set to "C" as well.  However, I want to keep the products to keep this descending order.  I am building a chart of products by year and want the products to keep the same order of appearance. However, when I apply this format I have created to a proc report, (applied to the product variable) it doesn't maintain the descending order. I am aware of assigning a value for HLO field, but  I haven't figured out how to use it yet.

 

So, in similar fashion to how one can make a notsorted proc format, how can I do the same when creating a format from a sas data set using cntlin?

 

THANK YOUUUUUUU!!!!!!!!

6 REPLIES 6
Reeza
Super User

You can include both variables, the formatted/unformatted and specify the unformatted as ORDER to force the correct order. You can use NODISPLAY to ensure its not shown on the report. 

 

But, if you're applying a format, it should sort using the underlying data, not the formatted value. 

sasiscool
Obsidian | Level 7

I am already aware of those tricks, but it still doesn't work. Another question:

 

if the table is product by year and the table looks like

 

                   Year 1     Year2        Year3

Apple             90          45           80

cherry           90            44           82

cake              78            60           75

pen               12             50           12

    

 

 

If each of the years have a different descending order, since some products sell at different rates per year, and I want to force the row order to appear according to the descending order of the last year, how do I dot that with my sas dataset format

Reeza
Super User

AFAIK there isn't a built in mechanism within PROC REPORT that will do this. 

Especially if you're using YEAR as an ACROSS variable. 

 

Instead you can create a data set in the order you want and then use PROC REPORT to display it as desired.

sasiscool
Obsidian | Level 7

So i can't just create a dataset with the most recent year descending, save it as a format with cntlin. And apply that to the proc report?

 

i have to create a dataset with each year? and don't create a format?

 

thank you for responding

Reeza
Super User

@sasiscool wrote:

So i can't just create a dataset with the most recent year descending, save it as a format with cntlin. And apply that to the proc report?

 

 


You can do this, but that wasn't clear to me when I first read your question. 

You would need to add in an order though, ie Apple = 1, Cherry = 2. Your current example has start=label which doesn't really create a format you want. So, you could create that and apply it to your data using PROC REPORT.

 

Here's an idea - untested:

 

data myformat;

set have;

label=put(_n_, z2.);;
start=start;
type = 'C';
fmtname = 'myFmt.';''

run;

proc format cntlin=myFormat;
run;

proc report data=myReportData nowd;
column ...... ;

define fruit  / f=$myFmt. order=formatted

run;;
ballardw
Super User

Time to show 1) some data and 2) the result for that data.

 


@sasiscool wrote:

So i can't just create a dataset with the most recent year descending, save it as a format with cntlin. And apply that to the proc report?

 

i have to create a dataset with each year? and don't create a format?

 

thank you for responding


 

It sounds like you are attempting to have a different sort order for a second variable for every year. If that is the case then you likely can't use Year as an across variable. If you absolutely must have a different order for every year than you really need to show what you expect that result to look like as you obviously cannot have a single row label involved.

 

For your first question about maintaining order you might try using the PRELOADFMT option in define block for the variable involved, which will require the use of the Order=data or Exclusive option. The format may require building with the NOTSORTED option. You also should show your proc report code as you may have been setting some option(s) that affect order of appearance that you haven't mentioned in this thread yet.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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