BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Billy1979
Calcite | Level 5

I have character dates and converting them to num date9. but fails to work for char date which is like "20060614".

 

dates are formatted 

20060614
20060531

 

im trying to get the format in to date format -

14JUN2006

i use the below step and it works for first record but doesnt work for second one.

 

i have tried a number of different ways - search quite a few different site but no go.

below is one of the examples i have tired.

 

data.work.temp;

set.despatch;

date=input(date_of_despatch, yymmdd10.);

format date date9.;

run;

 

but not getting any joy.

 

any help would be much appreciated. thanks

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

You NEVER want to see such a message in the log:

NOTE: Variable date_of_despatch_of_good is uninitialized.

This is one of the NOTEs that causes a log to be "dirty", see Maxim 25.

This NOTE means you typed the variable name incorrectly, or used the wrong dataset.

 

PS in an earlier message you wrote

so the original field is character field. i need to convert it to numeric date field. 

so looking at the columns

Name Date_of_despatch

Type Character

length 8

so you most probably mistyped the variable name.

View solution in original post

11 REPLIES 11
PaigeMiller
Diamond | Level 26
data want;
    set have;
    want_date=input(put(date,8.),yymmdd10.);
    format want_date date9.;
run;

 

 

This assumes your original dates are numeric, although you haven't actually said that.

--
Paige Miller
Billy1979
Calcite | Level 5
Thanks I will have a go in the morning and let you know how I get on. Cheers
Billy1979
Calcite | Level 5

so the original field is character field. i need to convert it to numeric date field. 

 

i hope that make sense

 

Tom
Super User Tom
Super User

The code works with the values you showed.

data have;
  input date_of_despatch $char10.;
cards;
20060614
20060531
;

data want;
  set have;
  date=input(date_of_despatch, yymmdd10.);
  format date date9.;
run;

Perhaps the values are not what you think they are. 

Here are some that do not work:

data have;
  input date_of_despatch $char20.;
  if _n_=4 then date_of_despatch=cats(date_of_despatch,'0D'x);
  if _n_=5 then date_of_despatch=cats('09'x,date_of_despatch);
cards;
20060531
2006O531
   20060531
20060531
20060531
;
3966   data want;
3967     set have;
3968     date=input(date_of_despatch, yymmdd10.);
3969     format date date9.;
3970   run;

NOTE: Invalid argument to function INPUT at line 3968 column 8.
date_of_despatch=2006O531 date=. _ERROR_=1 _N_=2
NOTE: Invalid argument to function INPUT at line 3968 column 8.
date_of_despatch=20060531 date=. _ERROR_=1 _N_=3
NOTE: Invalid argument to function INPUT at line 3968 column 8.
date_of_despatch=20060531
 date=. _ERROR_=1 _N_=4
NOTE: Invalid argument to function INPUT at line 3968 column 8.
date_of_despatch=	20060531 date=. _ERROR_=1 _N_=5
NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to
      missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      4 at 3968:8
NOTE: The data set WORK.WANT has 5 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
Billy1979
Calcite | Level 5
Thanks Tom,

I will have a go in the morning and let you know how I get my on.

Cheers
Billy1979
Calcite | Level 5

so the original field is character field. i need to convert it to numeric date field. 

so looking at the columns

Name Date_of_despatch

Type Character

length 8

data in the field - 20060614

 

i hope that make sense.

 

so i have done the below,

data want;
set have;
date=input(date_of_despatch, yymmdd10.);
format date date9.;
run;

 

when I run it I'm getting back blank fields - 

 

PaigeMiller
Diamond | Level 26

Works for me, I'm not getting blank output.

 

data have;
    date_of_despatch='20060614';
run;
data want;
    set have;
    date=input(date_of_despatch, yymmdd10.);
    format date date9.;
run;

 

 

Show us the ENTIRE LOG from your code. Copy the log as text and paste it into the window that appears when you click on the </> icon.

--
Paige Miller
Billy1979
Calcite | Level 5
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
22         
23         GOPTIONS ACCESSIBLE;
24         data want;
25          set atwd.atwd_despatches;;
26          date=input(date_of_despatch_of_good, yymmdd10.);
27          format date date9.;
28          run;



NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      26:13   
NOTE: Variable date_of_despatch_of_good is uninitialized.
NOTE: There were 558694 observations read from the data set ATWD.ATWD_DESPATCHES.
NOTE: MVA_DSIO.OPEN_CLOSE| _DISARM|         STOP| _DISARM| 2022-09-06T11:31:26,527+01:00| _DISARM| WorkspaceServer| _DISARM| SAS|
      _DISARM| | _DISARM| 558694| _DISARM| 28483584| _DISARM| 12| _DISARM| 21| _DISARM| 178712| _DISARM| 23761272| _DISARM|
      1.510000| _DISARM| 1.501806| _DISARM| 1978079485.025541| _DISARM| 1978079486.527347| _DISARM| 0.890000| _DISARM| | _ENDDISARM
NOTE: The data set WORK.WANT has 558694 observations and 17 variables.
NOTE: Compressing data set WORK.WANT decreased size by 80.98 percent.
      Compressed is 1398 pages; un-compressed would require 7352 pages.
NOTE: MVA_DSIO.OPEN_CLOSE| _DISARM|         STOP| _DISARM| 2022-09-06T11:31:26,567+01:00| _DISARM| WorkspaceServer| _DISARM| SAS|
      _DISARM| | _DISARM| 558694| _DISARM| 28483584| _DISARM| 12| _DISARM| 21| _DISARM| 178968| _DISARM| 23761536| _DISARM|
      1.520000| _DISARM| 1.537450| _DISARM| 1978079485.030051| _DISARM| 1978079486.567501| _DISARM| 0.880000| _DISARM| | _ENDDISARM
NOTE: PROCEDURE| _DISARM|         STOP| _DISARM| 2022-09-06T11:31:26,567+01:00| _DISARM| WorkspaceServer| _DISARM| SAS| _DISARM| |
      _DISARM| 1104273408| _DISARM| 28483584| _DISARM| 12| _DISARM| 21| _DISARM| 178976| _DISARM| 23761536| _DISARM| 1.530000|
      _DISARM| 1.551203| _DISARM| 1978079485.016803| _DISARM| 1978079486.568006| _DISARM| 0.890000| _DISARM| | _ENDDISARM
NOTE: DATA statement used (Total process time):
      real time           1.55 seconds
      cpu time            1.53 seconds
      



29         
30         GOPTIONS NOACCESSIBLE;
31         %LET _CLIENTTASKLABEL=;
32         %LET _CLIENTPROCESSFLOWNAME=;
33         %LET _CLIENTPROJECTPATH=;
34         %LET _CLIENTPROJECTNAME=;
2                                                          The SAS System                           09:28 Tuesday, September 6, 2022



35         %LET _SASPROGRAMFILE=;
36         
37         ;*';*";*/;quit;run;
38         ODS _ALL_ CLOSE;
39         
40         
41         QUIT; RUN;
42  

the example you posted Paige worked fine. 

but when I try and use it on the dataset it just returns blanks. I have attached the log. thanks

 

PaigeMiller
Diamond | Level 26

 

NOTE: Variable date_of_despatch_of_good is uninitialized.

 

 

This variable does not exist in your input data set atwd.atwd_despatches

--
Paige Miller
Kurt_Bremser
Super User

You NEVER want to see such a message in the log:

NOTE: Variable date_of_despatch_of_good is uninitialized.

This is one of the NOTEs that causes a log to be "dirty", see Maxim 25.

This NOTE means you typed the variable name incorrectly, or used the wrong dataset.

 

PS in an earlier message you wrote

so the original field is character field. i need to convert it to numeric date field. 

so looking at the columns

Name Date_of_despatch

Type Character

length 8

so you most probably mistyped the variable name.

Billy1979
Calcite | Level 5

Thanks Guys

should of double checked the fields properly.

thanks again.

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
  • 11 replies
  • 964 views
  • 0 likes
  • 4 in conversation