I have a multi variable data set. From that data set I am creating new data set with some specific variables and one new Date variable at the end.
The newly created Date Variable should contain week ending date. Below is the code i am writing to enter week ending date value, but when i open the data set the week ending date shows the "01/01/1960". Can someone guide me on this.
data test;
set existing (keep = list of variables i which WEDATE varibale is created);
if missing(wedate) then wedate = "08/17/2018";
else if wedate = "08/17/2018";
run;
assuming you are not representing as sas date constant and weddate is numeric sas date variable, the code may likely be
data test;
set existing (keep = list of variables i which WEDATE varibale is created);
if missing(wedate) then wedate ="17aug2018"d ;
run;
@novinosrin the given solutions is correct but i required the WEDATE in "mm/dd/yyyy" format. So for that i am using numeric value.
"scratching my head"
Do you mean you want to assign mmddyyyy format for your numeric sas dates for display?
sorry for confusion but you are right i want the value in WEDATE variable in MM/DD/YYYY format
@nishSAS wrote:
sorry for confusion but you are right i want the value in WEDATE variable in MM/DD/YYYY format
format wedate mmddyy10.;
That's all you need.
yes right
You know the difference between the formatted (displayed) value of a variable the the actual value?
If WEDATE is a sas date variable, that is a numeric variable with a date-format, than you must use "17aug2018"d to check if that date is stored in the variable, regardless of the date-format assigned to WEDATE.
No matter how a SAS date variable is displayed, SAS date literals in code are always written in the format "ddmmmyyyy"d, where mmm is the abbreviated name of the month.
If you want the SAS date variable to display as mm/dd/yyyy, assign it the MMDDYY10. display format.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.