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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 497 views
  • 0 likes
  • 4 in conversation