DATA Step, Macro, Functions and more

date variable

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 11
Accepted Solution

date variable

Hi,

 

Can someone tell me how to create a new variable named 'End_of_study' in the format 31/12/2012, which has to be the same for all entries/rows.

 

Regards,

 

 

 


Accepted Solutions
Solution
‎03-17-2017 05:01 AM
Super User
Posts: 5,257

Re: date variable

This question, and a lot more, can be learned in the free online SAS Programming course.

Data never sleeps

View solution in original post


All Replies
Solution
‎03-17-2017 05:01 AM
Super User
Posts: 5,257

Re: date variable

This question, and a lot more, can be learned in the free online SAS Programming course.

Data never sleeps
Super User
Posts: 5,085

Re: date variable

data want;

set have;

retain End_of_Study '31Dec2012'd;

format End_of_Study ddmmyys10.;

run;

Super User
Posts: 10,516

Re: date variable

Data want;

    set have;

    End_of_study = '31DEC2012'd;

    format End_of_study ddmmyy10.;

run;

 

Note that SAS only accepts one way to assign a date literal if you want to use it as a date value allowing use of the various date functions and formats.

Otherwise use a character value any way you want it.

Occasional Contributor
Posts: 11

Re: date variable

Thanks all of you for the support.

 

I've come accross another question. I've imported a date variable from excell; but the format for the date variable is in text and perhaps this is why the missing values are not marked in "." BUT are just blank cells in SAS Viewtable.

 

I appreciate if someone can advise on how to format the text to sas date value (such as 01/12/2011)

 

Cheers,

Tawfiq

Super User
Posts: 17,863

Re: date variable

What do,the date values look like now? 

 

It would be something like:

 

new_var = input (date_var, current_format.);

formate new_var ddmmyy10.;

Occasional Contributor
Posts: 11

Re: date variable

Hi Reeza,

The variable is Last_date (see below). It's format is $10. My purpose is to
change it to numeric so that the blank rows will be filled with (.) or
missing values and the date format (ddmmyy10.) would allow me to use this
variable for creating new vars.


Last_date

01/12/2011

05/08/2010


I used

LRec_date=input (Last_date, $10.);
format LRec_date ddmmyy10.;

BUT the error message is this (The format $ddmmyy was not found or could
not be loaded)
Super User
Posts: 10,516

Re: date variable

Your code:

LRec_date=input (Last_date, $10.);
format LRec_date ddmmyy10.;

 

Creates a text variable, that is what input using the informat $10. does.

Try

 

LRec_date=input (Last_date, ddmmyy10.);
format LRec_date ddmmyy10.;

Occasional Contributor
Posts: 11

Re: date variable

Hi,

 

It works. Thanks for the help!

Super User
Posts: 17,863

Re: date variable

@Tawfiq Sorry, current format, means how it currently appears ie mmddyy, not the $10. 

@ballardw solution is correct. 

Super User
Posts: 17,863

Re: date variable

Just a heads up to the free SAS training available that has been alluded to:

 

http://support.sas.com/training/tutorial/

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 152 views
  • 1 like
  • 5 in conversation