DATA Step, Macro, Functions and more

How can I combine Day Month and year to a single variable

Reply
Occasional Contributor
Posts: 14

How can I combine Day Month and year to a single variable

[ Edited ]

Hi All,

 

I have a data set like this : 

 

Day Mo Year Approve Disapprove No opinion

17 Aug 1998 62 32 6
10 Aug 1998 65 30 5
7 Aug 1998 64 32 4
29 Jul 1998 65 31 4
7 Jul 1998 61 34 5
22 Jun 1998 60 34 6

 

First 3 are in separate coloumns. I want to convert first 3 coloums, i.e, date, month, year  into a single coloumn with this way,

 

8-17-98 62 32 6

8-10-98 65 30 5

 

I tried to merge the cloumns using catx but after when I want to convert to dae, SAS throws an error since it takes it as a character variable.

Also, I tried, 

 

DATA Clinton1;
INFILE "/folders/myfolders/Module5/clinton.txt" FIRSTOBS = 2;
INFORMAT Day DAY2. Month MONNAME3. Year YEAR4.;
INPUT Day Month $ Year Approve Disapprove No_Opinion;
FORMAT Day DAY2. Month MONNAME3. Year YEAR4.;
 
(ALSO)
 
DATA Cinton2;
SET Clinton1;
DAY1 = INPUT(PUT(DAY1,2.),DAY2.);
MONTH1 = INPUT(PUT(MONTH1,$),MONNAME3.);
YEAR1 = INPUT (PUT(YEAR1,4.),YEAR4.);
FORMAT DAY1 DAY2. MONTH1 MONNAME3. YEAR1 YEAR4.;
DATE = MDY (MONTH1,DAY1,YEAR1);
FORMAT DATE1 YYMMDD10.;
RUN;

 

but no luck. 

 

Can anyone help please?

Super User
Posts: 19,789

Re: How can I combine Day Month and year to a single variable

Posted in reply to arunvaibhav

Use INPUT with DATE9. format

 

date_variable = input(catt(day, Mo, Year), date9.);
Ask a Question
Discussion stats
  • 1 reply
  • 518 views
  • 0 likes
  • 2 in conversation