DATA Step, Macro, Functions and more

Base sas

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 80
Accepted Solution

Base sas

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.

 


Accepted Solutions
Solution
‎02-28-2018 04:33 AM
Frequent Contributor
Posts: 80

Re: Base sas

Posted in reply to KurtBremser

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


All Replies
Super User
Posts: 10,599

Re: Base sas

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.)

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Frequent Contributor
Posts: 80

Re: Base sas

Posted in reply to KurtBremser
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.
Super User
Posts: 10,599

Re: Base sas

Please read my post again and assist me in helping you. Right now I don't know a jota more than before.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Frequent Contributor
Posts: 80

Re: Base sas

Posted in reply to KurtBremser

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;

Frequent Contributor
Posts: 80

Re: Base sas

Frequent Contributor
Posts: 112

Re: Base sas

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;
Super User
Posts: 10,599

Re: Base sas

This:

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

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

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Solution
‎02-28-2018 04:33 AM
Frequent Contributor
Posts: 80

Re: Base sas

Posted in reply to KurtBremser

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!!!

Super User
Posts: 10,599

Re: Base sas

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Super User
Posts: 9,857

Re: Base sas

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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