BookmarkSubscribeRSS Feed
thanikondharish
Fluorite | Level 6

data s1 ;
name=22122018 ;
run;

proc sql ;
select input(put(name,best.),ddmmyy10.) as date format=ddmmyyd10. from s1 ;
quit;

 

 

if run above program it gives 22-12-2020 but i want as it is date 

6 REPLIES 6
Ksharp
Super User

data s1 ;
name=22122018 ;
run;

proc sql ;
select input(put(name,best. -l),ddmmyy10.) as date format=ddmmyyd10. from s1 ;
quit;

thanikondharish
Fluorite | Level 6
what is best. -|
data_null__
Jade | Level 19

@thanikondharish wrote:
what is best. -|

 

-L left justify.

thanikondharish
Fluorite | Level 6
how it works could you explain that
Ksharp
Super User

Your code would keep lead blanks .

Like :   ___20122018  .So when you input() it ,your code only read the first 10 characters ___201220, that lead to wrong date.

 

if you use put(x,best. -L) would get rid of lead blanks and you would get:

20122018 and input() will correctly read it .

Kurt_Bremser
Super User

So you have a 8-digit number that should be a date. Convert it with

date = input(put(name,z8.),ddmmyy8.);

The z8. format makes sure that leading zeroes are not dropped.

What format you assign to the new variable depends on how you want it displayed.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 6 replies
  • 1957 views
  • 0 likes
  • 4 in conversation