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

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2004 views
  • 0 likes
  • 4 in conversation