sas >> SAS date conversion

by Midwest Financial Services » Wed, 06 Jun 2007 00:54:16 GMT

I have tried this every way I can think of, but I can't get the
results I want.

I have a dataset with a date field that is loaded from oracle as a
text field. The format is 'ccyymmdd' and appears like 20070605. I
want to convert it to a yymmdd8. I can not figure out why this will
not work.

Any suggestions would be greatly appreciated.

Dank U wel.



sas >> SAS date conversion

by shiling99 » Wed, 06 Jun 2007 01:08:26 GMT


On Jun 5, 12:54 pm, Midwest Financial Services < XXXX@XXXXX.COM >


Using input function with informat yymmdd8..

HTH

3235 data _null_;
3236 cdate='20070605';
3237 date=input(cdate,yymmdd8.);
3238 put cdate date yymmdd8.;
3239 run;

20070605 07-06-05
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds




sas >> SAS date conversion

by sbarry » Wed, 06 Jun 2007 01:08:42 GMT

On Jun 5, 12:54 pm, Midwest Financial Services < XXXX@XXXXX.COM >


What have you tried thus far? Show us your code and SASLOG results
with PUT _ALL_ for diagnostics. A data step and input the field using
INFORMAT YYMMDD8. will work.

Scott Barry
SBBWorks, Inc.



SAS date conversion

by Midwest Financial Services » Wed, 06 Jun 2007 01:50:26 GMT





Thanks for the replys.

code sample:

83 data set1;
84 set set1;
85 format date1 8.;
86 date2=input(date1,yymmdd8.);
87 put date2 yymmdd8.;
88 run;

log error:

NOTE: Numeric values have been converted to character values at the
places given by:
(Line):(Column).
86:20
NOTE: Invalid argument to function INPUT at line 86 column 14.



SAS date conversion

by mn_me » Wed, 06 Jun 2007 02:01:11 GMT

Hi!
Here's a possible approach :
I think the problem you are having is because the informat for
yymmdd8. is expecting a '-' between the yy, mm and dd fields. for
some reason, the format for yymmdd8 allows you to suppress that with
yymmddn8., but the informat doesn't.


data datechar(drop=yr mn dy);
format numdt yymmdd8.;

chardt = '20070605';
yr = substr(chardt,1,4);
mn = substr(chardt,5,2);
dy = substr(chardt,7,2);
numdt = mdy(mn,dy,yr);


run;






SAS date conversion

by matt.pettis » Wed, 06 Jun 2007 02:31:27 GMT

Hi,

I think that the problem is that when you are reading in the Oracle date
date1, it is being stored as a numeric value in your SAS dataset. The
problem comes because your statement:

date2=input(date1,yymmdd8.);

assumes that date1 is a character of the format 'yymmdd8'. I got this to
work by a put-input chain. try the following:

=================================================
DATA SET1;
INFILE DATALINES;
INPUT DATE1;
DATALINES;
20070605
;
RUN;

DATA SET2;
SET SET1;
DATE2 = INPUT(PUT(DATE1,8.),YYMMDD8.);
FORMAT DATE2 YYMMDD8.;
RUN;
PROC PRINT DATA=SET2; RUN;
=================================================

I get as output:

=================================================
Obs DATE1 DATE2

1 20070605 07-06-05
=================================================

you may need to change the date2 format to fit your needs.

HTH,
Matt

On Tue, 5 Jun 2007 17:50:26 -0000, Midwest Financial Services






SAS date conversion

by muthia.kachirayan » Wed, 06 Jun 2007 02:32:41 GMT

Try

date2 = input(put(date1,8.),yymmdd8.);

Muthia Kachirayan






SAS date conversion

by mn_me » Wed, 06 Jun 2007 02:36:08 GMT

Actually i just retried the input statement approach and it worked
this time ..

data datechar(drop=yr mn dy);
format numdt yymmdd8.;

chardt = '20070605';

numdt = input(chardt,yymmdd8.);

run;

Should work for you ...








SAS date conversion

by sbarry » Wed, 06 Jun 2007 04:14:39 GMT

On Jun 5, 12:54 pm, Midwest Financial Services < XXXX@XXXXX.COM >


Maybe it's time to explain "the results I want."?? (your wording
repeated)

If the SAS variable date1 is already stored in SAS as a numeric
variable, you need only use a SAS FORMAT in order to display the
variable's value outward in a desired format. There is no need to do
any conversion if you simply want to use this variable in a report --
use the SAS FORMAT statement or apply a specific SAS output format to
get the desired results. Also, if you intend to use the variable in
an expression, consider that the value is "days since Jan 1 1960" and
so other variables must be like-format (or converted with a SAS
function on-the-fly) at the point in a DATA step you intend to
reference your "date type" variable.

Scott Barry
SBBWorks, Inc.



sas date conversion

by shruthi » Fri, 30 Oct 2009 21:24:00 GMT

Hello all,

I have a character date and I have to convert it into numeric date

Chardate numericdate
2009-07-07 07JUL2009
2009-08-03 03AUG2009
2008-01 2008JAN
2007 2007
2009-07-11 11JUL2009

How can I write a code to do this conversion. thanks


sas date conversion

by goladin » Mon, 02 Nov 2009 00:02:05 GMT

Hi,

Using the following, you can convert them to numeric dates and then you can
apply your date format.

data test2;
set test;

if count(chardate,'-') > 1 then numdate = input(chardate,yymmdd12.);
else if count(chardate,'-') = 1 then numdate =
input(compress(chardate,'-'),yymmn6.);
else numdate = 1*chardate;
run;






Certified Advanced Programmer for SAS V9
Certified Basic Programmer for SAS V9
DataShaping Certified SAS Professional


sas date conversion

by Barry Schwarz » Tue, 03 Nov 2009 03:01:15 GMT

If the character date is already in a SAS variable, use the INPUT
function with an appropriate informat to convert the value to a SAS
numeric date value. If it is in a text file, use the INPUT statement
with the appropriate informat.

Once you have a SAS date value, use the appropriate format to display
the data.

On Fri, 30 Oct 2009 06:24:00 -0700 (PDT), shruthi



--
Remove del for email


sas date conversion

by gerhard.hellriegel » Tue, 03 Nov 2009 03:32:00 GMT

I assume that the date is like

yyyy-mm-dd

so the informats should be:

Chardate numericdate informat
2009-07-07 07JUL2009 yymmdd10.
2009-08-03 03AUG2009 yymmdd10.
2008-01 2008JAN
2007 2007 5.
2009-07-11 11JUL2009 yymmdd10.

for the 2008-01 I'd use the following:

mdy(input(scan(chardate,2,"-"),5.),1,input(scan(chardate,1,"-"),5.)

because that is no date.

Note that the numericdate like you present them are not native. That are
formatted values, otherwise

"2009-07-07" would be displayed like 18085.

Displaying a date-value like 2008JAN? Use yymon7.

A format to show only the year of a date-value - I don't know one. If you
want that, you can write a picture format, or use the YEAR function to
extract the year first.

Gerhard










Similar Threads

1. Adjusting for data concurrency and SAS date conversion

Please can yanyone help me with a SAS code that converts character date
variable such as 2004-08-04 into numeric variable?
 A much tougher problem. I am in the process of calculating dropout
rates for different school in the state.The data is at student level
data but some of the students are concurrently enrolled in more than
one school within the same school year. They are assigned different
exitcodes each time they leave a school and this exitcodes determine
which school I have to include the student in my calculation.

For example: student 1 has 3entries in my record because he starts on
March 11th 2005 at school A, withdrew on July 12th 2005(exitcode W5
which is transferred out), and on July 29 2005 starts at school B and
same time is is also in school school C's record. His exitcodes in
school's B and C are W1 and P respectively, meaning he tranfered from
school B and passed from school C.

My problem is that I am supposed to write a program that keeps track of
this movement and assigns vales to the include  and drop out categories
which is populated with each movement.(see attached spreadsheet). This
code should be able to overide previous determination assigned to
previuosly attended school depending on the later exit code. Final
include status is supposed to be the school with the last include code
of 1 and same is the case with final dropout status. Dropout rate in
the ratio of final dropout rstatus to final include status. Can you
please help me out with a workable code.

I will so much appreciate ANY form of assistance I can get from you in
this regard.

Sincerely,

Forster OKoli


 ID  cconcurret       schname        startdate             exitcode
include1    include2      include3  include4     dropout1   dropout2
dropout3    dropout4          include final status   dropout final
status
21211	N	WTYZ	11-Mar-2005	W5	1	0	0	0	0	0	0	0	         ?
 ?
21211	Y	AZBD	29-Jul-2005	W1	0	0	0	0	0	1	0	0	         ?
 ?
21211	Y	FESY	29-Jul-2005	P	0	1	1	0	0	1	0	0	         ?
?
21222	N	WSDE	4-May-2006	W2
21223	N	WBTF	4-Apr-2006	SE
21233	N	EDS	2-Feb-2006	W4
21234	N	QWER	4-Mar-2006	S12


**** Please note The code should be able to populate the red cells or
fields with each student movement and based on exitcode.

2. RE : SAS date conversion

3. SAS Date Values conversion

Dear All

I have a SAS dataset with a variable called acc_date with a Char 6
values as follows:

110305
062705
020205
020205
051005
071705
091405
100305
110605
110305
102305
082505
050405
010705
020705
052705
032105
040105
051905
070305
083005
092405
062505
072605
100305
;

I want to create a new variable that will have SAS date values as
follows:

Acc_date                New_acc_date
110305          03NOV2005
062705          27JUN2005
020205          02FEB2005
020205          02FEB2005
051005          05OCT2005
071705          and so on
091405
100305
110605
110305
102305
082505
050405
010705
020705
052705
032105
040105
051905
070305
083005
092405
062505
072605
100305
;

How can I do that?


Thanks

Yusuf Mohamedshah
Manager, HSIS Lab
Lendis Corporation
Federal Highway Administration
McLean, VA 22101
Phone: (202) 493 3464
Fax: (202) 493 3374

email:  XXXX@XXXXX.COM 
Web page: www.hsisinfo.org

4. Conversion of a text variable into a SAS date

5. sas to access date conversion

I need to convert a sas date to an access date. I can use sasdate =
datepart(accessdate) to convert to SAS, but I need to go the other
direction and convert sas to access. Any ideas? thanks

6. Macro variable problem: year/month date value conversion

7. Macro Date conversion

In macro variable Date1 I have following value

%put &Date1;
'08Jan2008'd

I wanted to convert the value in Date1 to form of yyyymmdd
Here I need 20080108

Can you please help me out

Raghu

8. date format conversion