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

Hi,

I have a dataset with dateofbirth

1950-04-13

1920-02-26

1940-03-23

I want to change to

04/13/1950

02/26/1920

03/23/1940

can I do this? Please let me know.

thank you in advance.

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If the variable is character it would be better just create a SAS date variable and assign the desired format for use.

If the variable is already as SAS date variable use the mmddyy10. format.

 

Best is to run Proc Contents on your data set and share the properties of the variable.

 

Here is an example of creating a SAS date valued variable from a character version:

data have;
  input x :$12. ;
datalines;
1950-04-13
1920-02-26
1940-03-23
;

data want;
  set have;
  datevar = input(x,yymmdd10.);
  format datevar mmddyy10.;
run;

There are lots of existing formats to display dates with in SAS, and you can even create your own, so the SAS date valued numeric such as datevar is the better option.

 

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Assuming these are actual SAS dates and not character strings, you simply need a FORMAT statement.

 

format dateofbirth mmddyys10.;
--
Paige Miller
ballardw
Super User

If the variable is character it would be better just create a SAS date variable and assign the desired format for use.

If the variable is already as SAS date variable use the mmddyy10. format.

 

Best is to run Proc Contents on your data set and share the properties of the variable.

 

Here is an example of creating a SAS date valued variable from a character version:

data have;
  input x :$12. ;
datalines;
1950-04-13
1920-02-26
1940-03-23
;

data want;
  set have;
  datevar = input(x,yymmdd10.);
  format datevar mmddyy10.;
run;

There are lots of existing formats to display dates with in SAS, and you can even create your own, so the SAS date valued numeric such as datevar is the better option.