BookmarkSubscribeRSS Feed
nishSAS
Calcite | Level 5

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;

8 REPLIES 8
novinosrin
Tourmaline | Level 20

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;

nishSAS
Calcite | Level 5

@novinosrin the given solutions is correct but i required the WEDATE in "mm/dd/yyyy" format. So for that i am using numeric value.

novinosrin
Tourmaline | Level 20

"scratching my head"

Do you mean you want to assign mmddyyyy format for your numeric sas dates for display? 

nishSAS
Calcite | Level 5

sorry for confusion but you are right i want the value in WEDATE variable in MM/DD/YYYY format

andreas_lds
Jade | Level 19

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.

Kurt_Bremser
Super User

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.

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 8210 views
  • 0 likes
  • 4 in conversation