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

HI,

 

I have 4 data sets containing date variables:

Table1 

date is in date format (21-Mar-2017)

table 2 

date is in character (21 Mar 2017)

table3

date is in character (21 mar 2017)

table4

date is in date format (21-mar-2017)

 

am trying to change the char to date format but it displays nil values. Please help. I need to merge the 4 tables.

 

1 ACCEPTED SOLUTION

Accepted Solutions
don21
Quartz | Level 8

Hi Have modified my previous query:

 

data test1(drop = PastDueSince);

      set Past_Due_Actual_Days2;

      format _PastDueSince date9.;

      _PastDueSince = input(trim(PastDueSince),date9.);

            PastDueSince = PastDueSince;

            rename _PastDueSince=PastDueSince;

run;

 

Works like charm!!!

View solution in original post

10 REPLIES 10
Kurt_Bremser
Super User

Please supply

- information about the date variables in all datasets with type, length and assigned format

- the code you already tried for those variables

- example values for numeric variables, raw without any format (use best.)

don21
Quartz | Level 8
Tabl 1 Date (char)
17-Jun-2016

Table 2 Date (Date)
6-Sep-17


I need to merge table 1 and 2 but when I try to conver char to date or date to char the variable is not piking any values.
don21
Quartz | Level 8

data Magellan3;

set Magellan2;

PastDueSince=input(PastDueSince,mmddyy16.);

run;

 

DATA Past_Due_Actual_Days2;

/*format PastDueSince date9.;*/

SET Past_Due_Actual_Days;

/*PastDueSince = f20;*/

PastDueSince =inputput(F20,f8.0),yymmdd.);

/*PastDueSince = PastDueSince - 21916;*/

RUN;

don21
Quartz | Level 8
 
Satish_Parida
Lapis Lazuli | Level 10

You are using wrong formats everywhere.

mmddyy16 is not informat for 17-Jun-2016 nor is yymmdd. You need to use date11.

 

data mylasr.test1;
Date1=input("15-jul-2015", date11.);
output;
run;
Kurt_Bremser
Super User

This:

data Magellan3;
set Magellan2;
PastDueSince=input(PastDueSince,mmddyy16.);
run;

can never work. You cannot change the type of a variable.

don21
Quartz | Level 8

Hi Have modified my previous query:

 

data test1(drop = PastDueSince);

      set Past_Due_Actual_Days2;

      format _PastDueSince date9.;

      _PastDueSince = input(trim(PastDueSince),date9.);

            PastDueSince = PastDueSince;

            rename _PastDueSince=PastDueSince;

run;

 

Works like charm!!!

Kurt_Bremser
Super User

For clarity's sake, I'd write it a little differently:

data test1 (
  drop=_PastDueSince
);
set Past_Due_Actual_Days2 (
  rename=(PastDueSince=_PastDueSince)
);
format PastDueSince date9.;
PastDueSince = input(trim(_PastDueSince),date9.);
run;

This makes it more readable with regards to what is converted to what.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Please refer to this post:

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

On how to create test data which shows what your data looks like, both data wise, but also structurally.  Its also a good idea to post code you have written.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 2613 views
  • 1 like
  • 4 in conversation