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?
Use INPUT with DATE9. format
date_variable = input(catt(day, Mo, Year), date9.);
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.
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.