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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1 reply
  • 11024 views
  • 0 likes
  • 2 in conversation