BookmarkSubscribeRSS Feed
arunvaibhav
Obsidian | Level 7

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?

1 REPLY 1
Reeza
Super User

Use INPUT with DATE9. format

 

date_variable = input(catt(day, Mo, Year), date9.);

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 1 reply
  • 11741 views
  • 0 likes
  • 2 in conversation