BookmarkSubscribeRSS Feed
cody
Calcite | Level 5
data TEST;
	set DATASET;
	monthIn = scan(Date,1);
	month = input(monthIn,4.);
	day = input(scan(Date,2),4.);
	year = input(scan(Date,3),4.);
run;

I have dates like  Date=9/1/2012

and my code returns monthIn=9 month=. day=1 year=2012.

 

Why does month not return month=9?

 

2 REPLIES 2
stat_sas
Ammonite | Level 13

Try this.

 

data TEST;
input date $;
monthIn = scan(Date,1);
month = input(monthIn,4.);
day = input(scan(Date,2),4.);
year = input(scan(Date,3),4.);
datalines;
9/1/2012
;
run;

 

proc print data=test;
run;

Patrick
Opal | Level 21

It's normally better to convert a string representing a date into an actual SAS date value. Once you've got a SAS date value you can format however you want to with either OOTB formats or your own picture format.

 

proc format;
  picture mdy_nums
    low-high ='month=%m Day=%d Year=%Y' (datatype=date)
    ;
quit;
 

data TEST;
  input date $;
  sas_date=input(date,mmddyy10.);
  format sas_date mdy_nums.;

  month=month(sas_date);
  day=day(sas_date);
  year=year(sas_date);

  datalines;
9/1/2012
;
run;

Capture.PNG

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
  • 2 replies
  • 865 views
  • 0 likes
  • 3 in conversation