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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 11837 views
  • 0 likes
  • 2 in conversation