SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
LOLO
Obsidian | Level 7

For some reason I can not figure this out. I have a variable, 'date' that is a numeric variable and has SAS value dates. For example: 

 

date=19632

 

Which refers to the date of 10/1/2013.  I want create a new variable 'newdate' that has the mmddyy10. format. 

 

How do I convert date to newdate?

 

Thanks!

 

Lorena

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Do you want it to be a SAS date variable with the proper format? Then do:

newdate = date;
format newdate mmddyy10.;

Or do you want it to be the string representation? Then do:

newdate = put(date,yymmdd10.);

which creates a character variable.

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

Do you want it to be a SAS date variable with the proper format? Then do:

newdate = date;
format newdate mmddyy10.;

Or do you want it to be the string representation? Then do:

newdate = put(date,yymmdd10.);

which creates a character variable.

ballardw
Super User

The flexibility of SAS date formats is one of the, IMHO, great features. Plus you have the ability to create custom ones as well.

The format controls the appearance for display and in analysis procedures can also be used to assign bins for grouping.

Except for some odd uses I recommend leaving date values as numeric as long as possible and just assign the format as desired for any specific use. Formats may be permanently assigned to the variable at creation but overridden with a format statement in any procedure.

 

data _null_;
   date=19632;
   put 'Date in date9. format=' date date9.;
   put 'Date in mmddyy10. format=' date mmddyy10.;
   put 'Date in worddate. format=' date worddate.;
   put 'Date in Julian  format=' date Julian.;
   put 'Date in year quarter format=' date YYQs.;
run;

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 33047 views
  • 0 likes
  • 3 in conversation