BookmarkSubscribeRSS Feed
alexanthonymaj0
Calcite | Level 5

Hi everyone,

 

I am getting all of my desired results, except my date formatting is incorrect. Currently, the date is formatted as "06-Aug-89" (it also comes up in the results this way) and I would like it to be  formatted as 06/11/1989. Does anyone have any suggestions? 

Here is my code:

 

libname employee '/home/alexanthonymaj0/my_courses/rahmansarker/c_8568';

data emp123;
          length FirstName $ 14 LastName $ 20 JobTitle $ 22;
          infile '/home/alexanthonymaj0/my_courses/rahmansarker/c_8568/emp_50490.csv' dlm=',';
          input EmployeeID FirstName $ LastName $ Gender $ Salary JobTitle $ Country $ HireDate $;
          format HireDate $ddmmyy. Salary dollar8.;
drop Gender Country;

run;

 

proc print data=emp123;
run;

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Hi and welcome to the SAS communities 🙂

 

Try this code 

 

libname employee '/home/alexanthonymaj0/my_courses/rahmansarker/c_8568';

data emp123;
          length FirstName $ 14 LastName $ 20 JobTitle $ 22;
          infile '/home/alexanthonymaj0/my_courses/rahmansarker/c_8568/emp_50490.csv' dlm=',';
          input EmployeeID FirstName $ LastName $ Gender $ Salary JobTitle $ Country $ HireDate $;
          format HireDate ddmmyy10. Salary dollar8.;
drop Gender Country;

run;

proc print data=emp123;
run;

 

In your original code, you specified  a character format (with a $). A date format is a numeric format. Also, remember to specify a length along with the format, as in ddmmyy10.

Astounding
PROC Star
With a slight modification to the end of the suggested INPUT statement which now reads:

... Hiredate $ ;

Change that to:

... Hiredate : date9. ;

That gives you a numeric date that you can format as ddmmyy10.

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