LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (June 2001, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 7 Jun 2001 09:34:59 -0400
Reply-To:     Howard Schreier <howard_schreier@ITA.DOC.GOV>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Howard Schreier <howard_schreier@ITA.DOC.GOV>
Subject:      Re: Macro date question

There are a couple of issues here.

First, as Ron has already shown, CALL SYMPUT, rather than %LET, is the way to create a macro variable during execution of a DATA step.

Second, SAS dates are numeric, whereas macrovariables are character. So it can't be done.

But one can create a macrovariable containing the string value representing a date constant. This can be used in a DATA step in any context where a numeric expression is appropriate.

Example ...

First create the pre-existing macrovariable containing a date in mm/dd/yy notation:

%let start=06/07/2001;

Now convert it:

data _null_; call symput('start1', quote(put(input("&START",mmddyy10.),date9.))||'d' ); run;

The expression used as the second argument to CALL SYMPUT first uses the INPUT function to convert the value to a numeric SAS date, the uses the PUT function to convert that back to a character value (07JUN2001), then wraps that in quotes and appends the letter "d", which conforms to the notational convention for a date constant. So the macrovariable START1 is created with the value


Now demonstrate use:

data _null_; nextday = &START1 + 1; put 'Next day is ' nextday weekdate.; run;

This just advances the date by one and prints it in the log. Result:

Next day is Friday, June 8, 2001

The log does *not* have a message about type conversion, because both operands in the addition are numeric.

On Wed, 6 Jun 2001 22:27:47 -0400, Crystal Vierhout <vierhout@UNITY.NCSU.EDU> wrote:

>I have probably an easy question. If a date in coming in SAS/Intranet as 01/01/99 what is the easiest way to make it a macro variable SAS date? Does anyone have a suggestion? > > >DATA TEMPGROUP; > >length STRING1 $3. DUMMY $3. ; > >START1=input("&START",mmddyy8.); > >if start1 ne . then %LET START1=&START1; > > > >Thanks > >Crystal > > > > > >

Back to: Top of message | Previous page | Main SAS-L page