02-10-2014 03:17 PM
Hello EG Users,
I have following had-coded %Let statement:
%LET birthdate = '01JAN2014'd;
I would like to change it to be flexible and equal to another variable from dataset
%LET birthdate = bdate;
Now bdate is of format mmddyy8.
How do I make sure that macro variable birthdate gets assigned value of variable bdate however is similar to '01JAN2014'd?
In summary, I am trying to understand what that 'd does to value inside text?
I tried using
format birthdate mmddyy8.;
as well as
format birthdate DATE9.;
but it did not work!?
02-10-2014 03:30 PM
The d in a literal like '01JAN2014'd tells SAS to treat the string as an internal date value which is numeric. There is a similar suffix, dt, for use with datetime literals.
If bdate is a variable in a dataset using %let will not assign its value to the macro variable birthdate. The main interface to assign values to macro variables from the data step is CALL SYMPUT. The syntax would generally be Call Symput ('birthdate', bdate); There are some cautions here though. If you dataset has multiple records the above syntax will only contain the value for the last record in the data set. Also, since macro variables are strings you probably want to control exactly what is the content and the default for dates probably won't be what you want.
If you want the value of bdate to become something like '01jand2014'd then you would probably be best off to create an additional variable and use funtions to create a variable of interest.
This code in a data step will create a macro variable birthdate with the date of bdate appearing as 'DDMONYYYY'd
length datestring $ 12;
datestring = cats("'",put(bdate,date9.),"'d");
02-10-2014 07:58 PM
Thats very helpful.
But I am seeing erratic behavior. Intermittently, when I try to print &birthdate, am getting warning
WARNING: Apparent symbolic reference birthdate not resolved.
How do I make sure that this does not happen?
02-10-2014 09:26 PM
This means the variable did not get created. If you are creating it from a data step then the data step might not have run or ran with zero observations so it never executed the CALL SYMPUT(). One way to avoid this is to create the macro variable first with a default value.
set patients ;
where pid = 5 ;
02-11-2014 06:17 AM
I think the below code may help you
%let st_dt = '11FEB2014'd;
/*to use the same date with diffrent date format*/
/* goes 90 days back to the date present in the macro which you are passing */
/*to use the same date in oracle quries (ie, connect to oracle ....) */