BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
soraiap
Fluorite | Level 6

Hey

 

I'm new to SAS, so maybe this is quite easy but i still haven't found a solution. So it goes:

 

I have a character like: 2018.01.01

(This was a phrase, and i did a SUBSTR to have only the date part)

 

I want to convert to date format. When i do: input(char,B8601DA8.) and format PTGDFDD8., nothing happens.

 

Can u help me pls?

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Please post test data in the form of a datastep of exactly what you have, and then show from that test data what you want out.  You are talking about several different things, first you say its yyyy.mm.dd, now its dd.mm.yyyy?  Then you don't seem to understan what the substr function does:

substr(<string>,<start position>,<number of characters>)

So in your case from position 10, take 11 characters which gives you this: "28.09.2018 ", so choosing the right informat:

data want;
  str="28.9.2018 ";
  dte=input(str,ddmmyy10.);
  format dte date9.;
run;

 

 

View solution in original post

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Use yymmdd informat:

data want;
  str="2018.01.01";
  dte=input(str,yymmdd10.);
  format dte date9.;
run;
Ksharp
Super User
data x;
 x='2018.01.01';
 y=input(x,yymmdd12.);
 format y date9.;
run;
soraiap
Fluorite | Level 6

i've tried that. the thing is when i did the substring of "via CRM (28.09.2018 / 10:00:00-12:00:00)" to get only the date part i had to do:
SUBSTR(t1.ATTRIBUTEVALUE, 10, 11)

which is weird, since it has more than two characters, but the result is 28.09.2018.

With that, how do i convert to date?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Please post test data in the form of a datastep of exactly what you have, and then show from that test data what you want out.  You are talking about several different things, first you say its yyyy.mm.dd, now its dd.mm.yyyy?  Then you don't seem to understan what the substr function does:

substr(<string>,<start position>,<number of characters>)

So in your case from position 10, take 11 characters which gives you this: "28.09.2018 ", so choosing the right informat:

data want;
  str="28.9.2018 ";
  dte=input(str,ddmmyy10.);
  format dte date9.;
run;

 

 

soraiap
Fluorite | Level 6

Thanks!!

Malathi13
Obsidian | Level 7

Hi,

I have a same question with dates. I have a character value for date of birth  which is 36223 and I want to convert it to any date format either date9 or yymmdd or mmddyy. My excel shows that date as 3/5/1999 but when I converted to sas date using date9 or any other formats it gives me 3/4/2059 which is very weird.

 

This is my program that I wrote to convert it to sas date format

 

data have;

set new;

birthdate=input(dob, yymmdd10.);

format birthdate date9.;

run;

 

I'm getting many missing values for other DOBs but some date of births that I get are not correct. As I mentioned above the character value of 36223 comes as 3/4/2059 after applying the format. Any help is greatly appreciated.

 

thanks

M

 

 

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