BookmarkSubscribeRSS Feed
ren2010
Obsidian | Level 7
Hi,
my input file has the following data:

date$
20071206
20011102

20071009
i use the following:
dt=input(date,yymmdd8.);
but my output looks like

07-12-06
01-11-02
.
07-10-09
because of the "." i can getting error invlaid argument used in input statement.

can anybody tell me how can i do this.

thanks
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You will want to use a SAS FORMAT statement or an ATTRIB stmt FMT= parameter to define a desirable SAS numeric DATE format to suit your needs. You must have a format being associated by default.

Scott Barry
SBBWorks, Inc.
Ksharp
Super User
Hi. I think 'yymmddn8' should be useful.
[pre]
dt=input(date,yymmdd8.);
format dt yymmddn8.;
put dt=;
[/pre]


Ksharp
Cynthia_sas
SAS Super FREQ
Hi:
In this instance, it would be useful to see your WHOLE program log and messages. I doubt that the '.' is what's generating the error message. I can use your same data in a program and yyddmm8. and do not get an error message.

There is a difference between the INFORMAT that you use to read in a date value and the FORMAT that you use to display a date value. The yymmdd8. is the correct format for reading in the date, since there are no delimiters in the date, it is translated from a character value to a numeric number of days since Jan 1, 1960.

The display of your date field is different however, yymmdd FORMAT (versus INFORMAT) wants there to be separators in a DISPLAYED date. so a FORMAT of yymmdd8. will result in the display you showed.

Here's the program I ran and the results are at the very bottom of the mail. Note the difference between the different PUT statements in the log. Each PUT statement uses a different FORMAT -- with the first PUT statement showing the internal value of the variables. Compare the results of the YYMMDD8. format with the YYMMDDN8. format -- the 'N' in the format name tells SAS not to use any separators for the date when the date is DISPLAYED.
[pre]
data chardate;
infile datalines;
input date $;
newdate = input(date,yymmdd8.);
put '***************************************';
put 'newdate is (internal value): ' newdate;
put 'newdate formatted 1: ' newdate date7.;
put 'newdate formatted 2: ' newdate yymmdd8.;
put 'newdate formatted 3: ' newdate yymmdd10.;
put 'newdate formatted 4: ' newdate yymmddn8.;
put 'newdate formatted 5: ' newdate worddate.;
return;
datalines;
20071206
20011102
;
run;
[/pre]

cynthia

The entire SAS log:
[pre]
296 data chardate;
297 infile datalines;
298 input date $;
299 newdate = input(date,yymmdd8.);
300 put '***************************************';
301 put 'newdate is (internal value): ' newdate;
302 put 'newdate formatted 1: ' newdate date7.;
303 put 'newdate formatted 2: ' newdate yymmdd8.;
304 put 'newdate formatted 3: ' newdate yymmdd10.;
305 put 'newdate formatted 4: ' newdate yymmddn8.;
306 put 'newdate formatted 5: ' newdate worddate.;
307 return;
308 datalines;

***************************************
newdate is (internal value): 17506
newdate formatted 1: 06DEC07
newdate formatted 2: 07-12-06
newdate formatted 3: 2007-12-06
newdate formatted 4: 20071206
newdate formatted 5: December 6, 2007
***************************************
newdate is (internal value): 15281
newdate formatted 1: 02NOV01
newdate formatted 2: 01-11-02
newdate formatted 3: 2001-11-02
newdate formatted 4: 20011102
newdate formatted 5: November 2, 2001
NOTE: The data set WORK.CHARDATE has 2 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.43 seconds
cpu time 0.01 seconds


311 ;
312 run;

[/pre]

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 16103 views
  • 0 likes
  • 4 in conversation