0
votes

I have a column that contains date values. So when imported as numeric, it shows 20668, 20669...etc. if I format it as yymmddn8, it shows 20160802 etc. However, what I really want is a numeric variable that shows 20160802. I have tried to create other to get day, month, year and then concatenate them. Unfortunately, the issue is if month and day is 1 digit, it would only show 201682. what would be the quickest way to achieve my goal. I guess a can turn the day and month variable to text and add 0 if day or month is less than 10. But this is not elegant and efficient. Please help. Thanks

2
My question would be why do you want to change the values? Keeping the dates as they are means you can utilise all the relevant date functions. If it's to display them in that way, then the format is designed for thatLongfish
Need more detail to explain. What are you inputting to? Why do you want this "numeric" 20160802? Where's it going (other dbms?) As it stands your question sounds like you're asking how to do something you should never do, except in very specific circumstances, but you may just be misunderstanding something.Joe

2 Answers

1
votes

You can just wrap an input around that format:

data test;
    date = 20668;
    full_date = input(put(date,yymmddn8.),best12.);
run;

The put is converting the date to character in the format as you want it to appear, and the input with the best12. format is converting it back to numeric in that format.

1
votes

It sounds like you just need to attach a format to your variable.

format date yymmddn8. ;

Try running this program to see a few of the different formats that are available for displaying dates.

data _null_;
  do date = 20668, 20669 ;
     put (6*date) (=10. =date9. =yymmddn8. =mmddyy10. =ddmmyy10. =yymmdd10.) ;
  end;
run;