11-28-2016 10:57 AM - edited 11-29-2016 09:55 AM
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:
11-28-2016 11:09 AM
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).
11-28-2016 11:21 AM - edited 11-28-2016 11:23 AM
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
11-28-2016 11:43 AM - edited 11-28-2016 11:51 AM
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):
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:
If your getting an error, then its likely to be a typo or something.
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.
11-28-2016 11:14 AM
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;