BookmarkSubscribeRSS Feed
jeffgreen
Fluorite | Level 6

Hi everyone,

 

I have imported a CSV file, and run proc tabulate. However, my variables 'season' and 'day' are in alphabetical order, and I want them to be inlogical order. Therefore, I have used CARDS to create 2 new datasets- 'seasons', which is the month in correct order, and 'orderday' which is the day in correct order.

 

My question is, how do I use these two datasets to create a proc tabulate like the one described above? I want to do this by using FORMAT and INFORMAT.

 

Thanks in advance.

2 REPLIES 2
Kurt_Bremser
Super User

It would be easier if you had SAS dates as values, as

  • the values sort correctly by themselves
  • you can use SAS-supplied formats for display
  • you can easily create custom formats (e.g. a MMDD format that omits the year) for such values
  • SAS procedures will use the formatted values, but can be instructed to keep the underlying order

Without that, I suggest you create a format for the pure month numbers:

proc format;
value mymonth
  1 = 'January'
  2 = 'February'
  3 = 'March'
/* and so on */
;
run; 

After applying this format to your month variable, you can then use ORDER=UNFORMATTED in the CLASS statement of PROC TABULATE.

ballardw
Super User

@jeffgreen wrote:

Hi everyone,

 

I have imported a CSV file, and run proc tabulate. However, my variables 'season' and 'day' are in alphabetical order, and I want them to be inlogical order. Therefore, I have used CARDS to create 2 new datasets- 'seasons', which is the month in correct order, and 'orderday' which is the day in correct order.

 

My question is, how do I use these two datasets to create a proc tabulate like the one described above? I want to do this by using FORMAT and INFORMAT.

 

Thanks in advance.


Since we would have to see exact values to make any sort of useable informat then provide the data step code with the cards statement. Copy the code and paste into a code box opened on the forum with the </> icon to prevent the forum message windows from reformatting text which can cause such code not to execute.

 

Most consistent would be to read the values into a numeric variable so the order is easier to maintain with an Order=data in proc tabulate and then a format to display the values.

 

Better might actually be to provide some example of the CSV file and the code you use to read that. Reading the CSV would be best time to use an informat to avoid creating additional variables that may be needed after these values that don't sort as desired.

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