Help using Base SAS procedures

Character to Date format

Reply
Contributor
Posts: 25

Character to Date format

Hi All,
I've assigned below macro.
%let date = 20090723(yymmddn8.)
but the question is the i want to change it in to Date ormat.
using this macro i need another variable "newdate" is in any type of Date format. like date9., mmddyy...........

Thanks in Advance
Alankar
Trusted Advisor
Posts: 2,113

Re: Character to Date format

I think what you want is

newdate=INPUT(&date, yymmdd8.);

(Assuming yout %LET is actually

%LET date = 20090723;
)
N/A
Posts: 0

Re: Character to Date format

I assume you are asking how to set a dataset variable from the value of a macro variable. In this case you could use the INPUT function.

newdate=input("&date",mmddyy.);

If you want to control how this new numeric variable is displayed then you can attach a format to it.

If you want to store the value into a character variable then you could use the PUT function.

newdatef = put(newdate,date9.);
Super Contributor
Super Contributor
Posts: 3,174

Re: Character to Date format

Your final use of this data-string is unclear - so does the data need to be a SAS date variable with an internal representation (days since Jan 1, 1960) or are you expecting a formatted value (1/1/2009)?

Regardless, if you want to use SAS macro language only, you will need to look into using %SYSFUNC and at least the INPUT function to convert the character-representation to a SAS DATE value, and then if you also want to re-format the string to display a formatted DATE, you will again use %SYSFUNC and the PUTN function with the appropriate SAS format.

Suggest searching the SAS support http://support.sas.com/ website using keywords from the information provided in this post reply -- you will find both SAS-hosted documentation and also supplemental technical/conference papers on this topic.

Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 3 replies
  • 148 views
  • 0 likes
  • 4 in conversation