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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.