BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Tawfiq
Fluorite | Level 6

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,

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
LinusH
Tourmaline | Level 20

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

Data never sleeps

View solution in original post

10 REPLIES 10
LinusH
Tourmaline | Level 20

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

Data never sleeps
Astounding
PROC Star

data want;

set have;

retain End_of_Study '31Dec2012'd;

format End_of_Study ddmmyys10.;

run;

ballardw
Super User

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.

Tawfiq
Fluorite | Level 6

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

Reeza
Super User

What do,the date values look like now? 

 

It would be something like:

 

new_var = input (date_var, current_format.);

formate new_var ddmmyy10.;

Tawfiq
Fluorite | Level 6
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)
ballardw
Super User

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.;

Tawfiq
Fluorite | Level 6

Hi,

 

It works. Thanks for the help!

Reeza
Super User

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

@ballardw solution is correct. 

Reeza
Super User

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

 

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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