Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert a date to character 1

Status
Not open for further replies.

a0f6459

Programmer
Dec 5, 2007
13
US
Currently I have a field that contains datetime called image_date.

However, I only want the month and year. This is what I have done.

PROC SQL;
CREATE table test as
SELECT store_code, datepart(image_date) as image_date format=$MONYY7., cnt
FROM &image_store.
;
quit;

Of course the problem is that even though I see month and year in the table, it is actually still stored in numeric format by sas. What I want to be able to do is do a group by on the image date (by month). But what is happening is it is grouping it by day since the datepart() really did not do anything to the actual date. Is there any solution out there in which I can just extract the month and year from the datetime and then be able to group that field by month?

Please let me know if furhter clarificatio is needed.

Thanks

 
You could do something like this:

Code:
PROC SQL;
 CREATE table test as
 SELECT store_code, put(datepart(image_date),yymmd7.) as image_date2,  cnt
 FROM &image_store
 group by image_date2
 ;
quit;

The PUT function will output a text string. I used a format that has the year before the month so that your ordering would be chronologically. (You can use other formats so that you can order and group your data any way you like.)

Hope this helps you.
Klaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top