BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

i have 2 columns,

 

var/value/type

month = feb    <-- char

day=1             <-- num

 

i want to convert them into date format like,

 

var=date

value= 1 Feb 2017 or 02/01/2017

 

 

can someone please help...Thank you...

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Do you want a character value:

length datechar $ 11.; /* this assumes that month will only ever be 3 characters, it will need to be longer if that is not the case*/

datechar = catx(' ',day,month,'2017'); or possibly catx(' ',day,propcase(month),'2017') depending on how you want capitalization of the month.

 

or a SAS date value? (if your month is longer than 3 characters or a non-standard abbreviation then extra logic will be needed*/

date = input(catt(day,month,'2017'),date9.);

format date date9.;

 

If you don't have a year value then you need to provide one explicitly.

View solution in original post

5 REPLIES 5
ballardw
Super User

Do you want a character value:

length datechar $ 11.; /* this assumes that month will only ever be 3 characters, it will need to be longer if that is not the case*/

datechar = catx(' ',day,month,'2017'); or possibly catx(' ',day,propcase(month),'2017') depending on how you want capitalization of the month.

 

or a SAS date value? (if your month is longer than 3 characters or a non-standard abbreviation then extra logic will be needed*/

date = input(catt(day,month,'2017'),date9.);

format date date9.;

 

If you don't have a year value then you need to provide one explicitly.

woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10
thank you Ballardw,

actually I need sas date value,
when try using this,

date = input(catt(day,month,'2017',date9.));

it says "expecting an arithmetic expression" for "date9." in date= statement pointing to "syntax error"



Reeza
Super User

When building nested functions, testing one at a time.

 

Your parenthesis is in the wrong location, you're trying to concatenate all values include Date9.

 

Try moving the parenthesis to after 2017. 

You probably want a format applied as well, to display it the way you want 

 

 

ballardw
Super User

I corrected the code in my post for the SAS date, I didn't see that my first) hadn't been typed.

woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10
Thank you Ballardw,
you are right, after your first comment, I was trying to put 2 parenthesis all the way in end not realizing correct syntax -
perfectly worked fine...

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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