BookmarkSubscribeRSS Feed
Boa
Obsidian | Level 7 Boa
Obsidian | Level 7

Hi sasusers, i have a dataset of 300000 + datas and with orderdate as my only column and it contains Datetime as well.

How can i show all the month in a 2008? For example, Jan , Feb , Mar without the days value. I am doing this for a bar chart wizard.

 

Some data in my orderdate:

 

Orderdate

13OCT07  00:00:00

2JUN08    00:00:00

2JAN08    00:00:00

1JAN08    00:00:00

1DEC08    00:00:00

5DEC09    00:00:00

 

 

8 REPLIES 8
PeterClemmensen
Tourmaline | Level 20

are your date/datetime variables stored as you have posted? 🙂

Boa
Obsidian | Level 7 Boa
Obsidian | Level 7

Yes they are stored in the dataset already.   is it possible to just show the month in the year 2008 instead of just printing the date and month together?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

Well:

data want;
  set have (where=(year(datepart(orderdate))=2008));
  mnth=month(datepart(orderdate));
run;

This now only contains 2008 data, and has a variable mnth which contains the 2 digit month (which you can format to other text if you want, look up MONNAME. format).

Boa
Obsidian | Level 7 Boa
Obsidian | Level 7

Firstly, thanks for the code. I tried and used it for my program, the code looks fine but there is no output in the orderdate. 

 

i would like to ask why would you put a bracket behing a where clause? if you put that, the where clause wont run and it shows error. 

And what is mnth? am i creating a new variable just for month itself? Kindly advise. Thanks 🙂 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

Well, you should post some test data - in the form of a datastep - so I can run it and see.  I cant tell offhand what is happening without code/log/test data.  Follow this post (only need a few rows):

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

The where clause is correct, it is an option on the input dataset, so the where is applied as the data is read.  You can put dataset options in several places:

https://onlinecourses.science.psu.edu/stat481/node/16

 

If your getting an error, then its likely to be a typo or something.

 

Example:

data have;
  orderdate="13OCT2007:00:00:00"dt; output;
  orderdate="02JUN2008:00:00:00"dt; output;
  orderdate="02JAN2008:00:00:00"dt; output;
  format orderdate datetime.;
run;

data want;
  set have (where=(year(datepart(orderdate))=2008));
  mnth=month(datepart(orderdate));
run;

 

Mnth is a new variable, it is numeric, and contains the month number within the year, i.e. Jan=1.  You can then format this number using monname to display as Jan.

Boa
Obsidian | Level 7 Boa
Obsidian | Level 7

ok thanks., i have another question that is similar to this, i probably would post another question. But i doubt it would use monname3. 

ballardw
Super User

Displaying values is often best accomplished with a Format. SAS provides tools to create custom formats for date, time and datetime values that you can customize.

 

proc format ;
  picture dtmon (default=3)
  . = " "
  low - high = '%b'   (datatype=datetime)
  ;
run;

Use the dtmon format in any procedure you want to display the 3-letter month abbreviation. This example will print the first 10 observations using the format:

 

proc print data=work.date (obs=10);
   var orderdate;
   format orderdate dtmon.;
run;
Peter_C
Rhodochrosite | Level 12
it is about the bar-chart wizard (not the data).
In SAS/Graph, there is an approach which solves this problem by defining all the "mid-points" you want

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 1759 views
  • 0 likes
  • 5 in conversation