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

data have;

aestdtc="02mar2010";

aeendtc="03jul2010";

end;

how to convert these dates like 02-03-2010 and 03-07-2010?

thanks

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Use the input function with SAS date informats (such as date9.) to convert strings to SAS dates, and make sure you associate a SAS date format (such as ddmmyyd10.) with SAS dates:

data have;
aestdtc="02mar2010";
aeendtc="03jul2010";
aestdt = input(aestdtc, date9.);
aeendt = input(aeendtc, date9.);
format aestdt aeendt ddmmyyd10.;
run;

proc print; run;

 

PG

View solution in original post

8 REPLIES 8
mkeintz
PROC Star

Just as   x=3   assigns a numeric literal (3) to x

  and

     name='paddyb'  assigns a character literal (paddyb) to name

  

 

aestdtc="02mar2010"d  assigns a date literal   ("02mar2010"d) to the variable AESTDTC, which now contains a sas date value.

 

You only have to assign one of many date formats (date9., yymmdd10.  yymon7. ...) to see it displayed in human-interpretable form.  In your case, assign the format ddmmyy10:

 

    format aestdtc ddmmyyd10.;

 

Note: the trailing "d" in ddmmyyd10. represents a dash.  There are other separators available.

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
paddyb
Quartz | Level 8

Thanks for reply.Actually in my aestdtc have 100 obs and i want to convert all

so my question is how to apply  'aestdtc'd

mkeintz
PROC Star

Do you have 100 observations in a sas dataset, where aestdtc is a character variable?  Show the input data set please, in the form of a sas data set or raw data file. 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
PGStats
Opal | Level 21

Use the input function with SAS date informats (such as date9.) to convert strings to SAS dates, and make sure you associate a SAS date format (such as ddmmyyd10.) with SAS dates:

data have;
aestdtc="02mar2010";
aeendtc="03jul2010";
aestdt = input(aestdtc, date9.);
aeendt = input(aeendtc, date9.);
format aestdt aeendt ddmmyyd10.;
run;

proc print; run;

 

PG
paddyb
Quartz | Level 8

thanks it works for full date but not working where aestdtc="mar2014"if day is misssing

mkeintz
PROC Star

You didn't mention that.  Before I respond, are there other incoming date formats that you will need to accomodate?

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
paddyb
Quartz | Level 8

sorry didnt mention it.thr r few dates in which month and day is missing

PGStats
Opal | Level 21

What date to you want to convert aestdtc="mar2014" into?

PG

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 1231 views
  • 1 like
  • 3 in conversation